【发布时间】:2021-07-13 03:24:11
【问题描述】:
我有shiny 应用程序,默认情况下它会显示一个绘图。当我单击actionButton() 时,它会隐藏它,但我想再次单击相同的actionButton() 并显示它等等。
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("hideshow_plot",
"HideShow plot")
),
mainPanel(
plotOutput(outputId = "car_plot")
)
)
)
server <- function(input, output) {
showPlot <- reactiveVal(TRUE)
observeEvent(input$hideshow_plot, {
showPlot(FALSE)
})
output$car_plot <- renderPlot({
if (showPlot()){
plot(cars)
}
else{
}
})
}
shinyApp(ui = ui, server = server)
【问题讨论】: