参考:Using Action Buttons主要是要设计一个全局变量,可以进行多次active即可:

    1. library(shiny)
    2. ui <- fluidPage(
    3. actionButton(inputId = "runif",label = "runif"),
    4. actionButton(inputId = "reset",label = "reset"),
    5. textOutput("text"),
    6. plotOutput("hist")
    7. )
    8. server <- function(input, output) {
    9. v <- reactiveValues(data = NULL)
    10. observeEvent(input$runif, {
    11. v$data <- runif(100)
    12. })
    13. observeEvent(input$reset, {
    14. v$data <- NULL
    15. })
    16. output$hist <- renderPlot({
    17. if (!is.null(v$data)) {
    18. hist(as.numeric(v$data))
    19. }
    20. })
    21. output$text <- renderText({
    22. if (!is.null(v$data)) {
    23. paste("v$data is ploted to histogram")
    24. } else {
    25. paste("v$data is reseted to NULL")
    26. }
    27. })
    28. }
    29. shinyApp(ui = ui, server = server)

    截图_20210112174925.gif
    runif和reset控件都是在控制v$data这个变量!