R 使用下载处理程序将ggplot图像保存到
我正在用Shinny开发一个应用程序。在Shinny中,我使用action按钮渲染一个简单的绘图。我已经包括了一个下载按钮来下载现在在UI中的绘图。从我的代码(plot3) 我尝试了下面的代码,以保存图像,但我得到一个错误 找不到打印输入 谁能告诉我哪里出了问题 下面是我的代码供参考。 用户界面:R 使用下载处理程序将ggplot图像保存到,r,ggplot2,shiny,R,Ggplot2,Shiny,我正在用Shinny开发一个应用程序。在Shinny中,我使用action按钮渲染一个简单的绘图。我已经包括了一个下载按钮来下载现在在UI中的绘图。从我的代码(plot3) 我尝试了下面的代码,以保存图像,但我得到一个错误 找不到打印输入 谁能告诉我哪里出了问题 下面是我的代码供参考。 用户界面: uilibrary(闪亮) 图书馆(shinydashboard) 实验室的用户界面输入错误(title=“Probability”,x=“Date”,y=“True Probability”)@A.
uilibrary(闪亮)
图书馆(shinydashboard)
实验室的用户界面输入错误(title=“Probability”,x=“Date”,y=“True Probability”)@A.Suliman我现在就更正它。虽然我得到了绘图,但问题是我无法先下载绘图。服务器函数的args后面有右括号。然后您将收到警告:plotInput中出错:找不到函数“plotInput”
@Suliman,我可以下载图像。但随后应用程序将自动关闭。我想让它运行。对不起,你所说的应用程序会自动关闭。我在Rstudio和web浏览器中运行该应用程序,下载后没有任何异常情况发生。
ui <- tabItem(tabName = "models2",
fluidPage(
fluidRow(
infoBoxOutput("overview")
),
fluidRow(
actionButton("result1","Generate Result"),
downloadButton('downloadPlot','Download Plot'),
plotOutput("plot3")
)
))
server <- function(input,output,session{
output$overview <- renderValueBox({
valueBox(
paste("91"),"Overview",icon=icon("hourglass"),
color="green"
)
})
observeEvent(input$result1,{
output$plot3 <- renderPlot({
ggplot(data=timedata, aes(x=dat1, y=yes, group=3))+
geom_point(shape=1)+
coord_cartesian(xlim=c(dat1_xlowlim,dat1_xhighlim))+
labs(title="Probability",x="Date",y="True probability")
})
})
output$downloadPlot <- downloadHandler(
filename = function(){paste(input$plot3,'.png',sep='')},
content = function(plot3){
ggsave(plot3,plotInput())
}
)
})
library(shiny)
library(shinydashboard)
ui <- tabItem(tabName = "models2",
fluidPage(
fluidRow(
infoBoxOutput("overview")
),
fluidRow(
actionButton("result1","Generate Result"),
downloadButton('downloadPlot','Download Plot'),
plotOutput("plot3")
)
))
server <- function(input,output,session){
output$overview <- renderValueBox({
valueBox(
paste("91"),"Overview",icon=icon("hourglass"),
color="green"
)
})
data <- reactiveValues()
observeEvent(input$result1,{
data$plot <- ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width))+
geom_point(shape=1)})
output$plot3 <- renderPlot({ data$plot })
output$downloadPlot <- downloadHandler(
filename = function(){paste("input$plot3",'.png',sep='')},
content = function(file){
ggsave(file,plot=data$plot)
}
)
}
shinyApp(ui, server)