简体   繁体   中英

The downloadablePlot Shiny Module breaks down my shiny app upon launching

I have the shiny app below and I would like to know how I can download a plot using the downloadablePlot Shiny Module. When I launch the app the whole app breaks down.

library(shiny)
library(periscope)
ui <- fluidPage(
  plotOutput("plot"),
  downloadablePlotUI("object_id1", 
                     downloadtypes = c("png", "csv"), 
                     download_hovertext = "Download the plot and data here!",
                     height = "500px", 
                     btn_halign = "left")
)

server <- function(input, output) {
  output$plot<-renderPlot(plot(iris))
  plotInput = function() {
    plot(iris)
  }
  callModule(downloadablePlot,
             "object_id1", 
             logger = ss_userAction.Log,
             filenameroot = "mydownload1",
             aspectratio = 1.33,
             downloadfxns = list(png = plotInput()),
             visibleplot = plotInput())
  
}

shinyApp(ui = ui, server = server)

Try removing the brackets after plotInput when passing it as an argument

library(shiny)
library(periscope)
ui <- fluidPage(
  plotOutput("plot"),
  downloadablePlotUI("object_id1",
                     downloadtypes = c("png", "csv"),
                     download_hovertext = "Download the plot and data here!",
                     height = "500px",
                     btn_halign = "left")
)

server <- function(input, output) {
  output$plot<-renderPlot(plot(iris))
  plotInput = function() {
    plot(iris)
  }
  callModule(downloadablePlot,
             "object_id1",
             logger = ss_userAction.Log,
             filenameroot = "mydownload1",
             aspectratio = 1.33,
             downloadfxns = list(png = plotInput),
             visibleplot = plotInput)

}

shinyApp(ui = ui, server = server)

In shiny, when passing functions / reactives around, you usually need to avoid appending them with () as doing so evaluates them. In the above example, you were returning the output of plotInput instead of the function itself

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM