I'm using shinyscreenshot
to download a plot that exists in tab1 of my shiny app. When I try to use the exact same method but place the download button in tab2 (still wanting plot from tab1), this fails. How can I make this work?
Simple, self-contained, minimal reprex :
library(shiny)
library(shiny.semantic)
library(semantic.dashboard)
library(shinyscreenshot)
library(ggplot2)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(side = "left",
sidebarMenu(
menuItem(tabName = "tab1", text = "tab1", icon = icon("home")),
menuItem(tabName = "tab2", text = "tab2", icon=icon("home")))),
dashboardBody(
tabItems(
tabItem(
tabName = "tab1",
fluidRow(
box(title = "tab1",
column(5,
plotOutput("myplot")),
actionButton("download_plot_test1", "download_plot_test1") #Screenshot the plot
))),
tabItem(
tabName = "tab2",
fluidRow(
box(title = "tab2",
width = 7,
column(5,
actionButton("download_plot_test2", "download_plot_test2"))))))))
server <- shinyServer(function(input, output) {
#Render simple ggplot
output$myplot <- renderPlot({ggplot(mtcars, aes(x=cyl, y=mpg)) + geom_point()})
#Test1 (it works)
observeEvent(input$download_plot_test1, {
screenshot(id="myplot", scale=2)
})
#Test2 (does not work?)
observeEvent(input$download_plot_test2, {
screenshot(id="myplot", scale=2)
})
}) #End shinyServer
#Run the app
shinyApp(ui, server)