Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

r - Update content on server only after I click action button in Shiny

I'm having problems with reactive output in shiny server in R.

What I want to do is create a plotly plot that uses values calculated based on input.

The output has to be updated only after I click submit/done button and the output has to be calculated as many times as needed.

What I managed to do was to update the content independently of the submit button (the submit button simply has no function) and the plot changed immediately after I changed 1 value.

What I would like to do is to change the plot only after I specify all the values of parameters I want.

Here is a minimal example of my ui.R code:

    shinyUI(fluidPage(
      titlePanel("Wages in Year 2016 for Czech Republic in CZK"),
       sidebarPanel(

      conditionalPanel(condition = "input.conditionedPanels==7",
                 selectInput("Age", "Age", choices = vek_mod$Vek, selected = "23-27"),
                 selectInput("ChosenSex", "Your sex", choices = pohlavi_mod$Pohlavie, selected = "Zena"),
                 actionButton("Button", "Done"),
                 p("Click so changes will take effect.")
      ),
        mainPanel(
         tabsetPanel(
           ...
            tabPanel("Minimal_Example", textOutput("Minimal_Example"), value = 7)
            ...
            , id = "conditionedPanels"
    )
   )
  )
 )

and here is the server.R code:

...
  output$Minimal_Example <- renderPrint({

    Age <- input$Age
    Sex <- input$ChosenSex
    c(Age, Sex)
    })
...

I tried a lot of things with observeEvent() as well as eventReactive() but so far nothing has worked for me.

If you want to see how the code behaves like, look here: http://52.59.160.3:3838/sample-apps/Mzdy_ShinyApp/

Tab is called Minimal_Example

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

submitButton is just made for this.


If you want to use actionButton instead, simply use isolate to avoid refresh based on value changes, and add the input$Buttonin the code like:

output$Minimal_Example <- renderPrint({
  input$Button
  Age <- isolate(input$Age)
  Sex <- isolate(input$ChosenSex)
  c(Age, Sex)
}) 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...