Update content on the server only after clicking the action button in Shiny
I am having problems with reactive output on a shiny server in R.
I want to create a graphical graph that uses values โโcalculated based on input.
The output should only be updated after clicking the submit / do button, and the output should be calculated as many times as needed.
I was able to update the content regardless of the submit button (the submit button just has no function) and the graph changed immediately after I changed the value to 1.
What I would like to do is change the graph only after I have specified all the parameter values โโthat 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 have tried many things with the registerEvent () function as well as eventReactive (), but nothing has worked for me so far.
If you want to see how the code behaves, look here: http://52.59.160.3:3838/sample-apps/Mzdy_ShinyApp/
The tab is called Minimal_Example
thank
source to share
submitButton
just for that.
If you want to use actionButton
instead, just use isolate
to avoid update based on value changes and add input$Button
in code like:
output$Minimal_Example <- renderPrint({
input$Button
Age <- isolate(input$Age)
Sex <- isolate(input$ChosenSex)
c(Age, Sex)
})
source to share