Shiny Reactivity

前端 未结 2 1460
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 18:47

I\'ve got an application with a large number of parameters. Each parameters has lots of granularity which make finding the desired one a pain. This causes the reactive porti

相关标签:
2条回答
  • 2020-12-31 19:39
    • change getY so that all but the first line is wrapped in isolate({ ... })
    • change submitButton to actionButton
    • add a line inside of renderPlot to read the new actionButton
    0 讨论(0)
  • 2020-12-31 19:49

    The answer was given by Joe Cheng in a comment above, but seeing that the OP had difficulty understanding it, I write it out explicitly below, for the record:

    # ui.R
    
    library("shiny")
    shinyUI(
      pageWithSidebar(
        headerPanel("Example")
        ,
        sidebarPanel(
          sliderInput("N", "Number of Samples", min = 2, max = 1000, value = 100)
          ,
          actionButton("action", "Resample")
        )
        ,  
        mainPanel(
          tabsetPanel(      
            tabPanel("Plot", plotOutput("plotSample"))
            ,
            id = "tabs1"
          )
        )
      )
    )
    
    # server.R
    
    library("shiny")
    shinyServer(
      function(input, output, session) { 
        Data <- reactive({
            input$action
            isolate({ 
                return(rnorm(input$N))
                return(x)
            })
        })
      output$plotSample <-renderPlot({
          plot(Data())
        } , height = 400, width = 400
      )
    })
    

    Note that having input$action inside reactive(), where "action" is the actionButton's inputID, is enough to trigger a new rendering of the plot. So you need only one actionButton.

    0 讨论(0)
提交回复
热议问题