Shiny: plot results in popup window

前端 未结 3 939
[愿得一人]
[愿得一人] 2020-12-28 22:19

I am trying to build a web app with shiny and I would like to display the resulting plot of a R function in a popup window rather than in mainPanel. For instance, for the b

3条回答
  •  一整个雨季
    2020-12-28 22:40

    Using native Shiny functionality

    library(shiny)
    
    ui <- fluidPage(
      actionButton("go", "Go"),
      numericInput("n", "n", 50)
    )
    
    server <- function(input, output) {
      randomVals <- eventReactive(input$go, {
        runif(input$n)
      })
      
      output$plot <- renderPlot({
        hist(randomVals())
      })
      
      observeEvent(input$go, {
        showModal(modalDialog(
          plotOutput("plot"),
          footer = NULL,
          easyClose = TRUE
        ))
      })
    }
    
    shinyApp(ui, server)
    

提交回复
热议问题