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