I have a somewhat complicated app which queries APIs and databases.
The user inputs some values, some of which change the data and thus require calling the API again, while others only change how the data is manipulated.
The whole thing is kicked off by an action button.
I would like to only update the data when both the action button is pressed, and the input relating to the data is changed. If the input relating to the data is not changed, I want to keep the data as is.
The following example captures what I want. a solution would mean that if you change n, the plot data changes when you press go. But if n stays the same, and you change the color (and press Go), only the color changes and not the underlying data.
Any help would be greatly appreciated!
# Global variables can go here
n <- 200
# Define the UI
ui <- bootstrapPage(numericInput('n', 'Number of obs', n),
numericInput('color', "Numeric code for color", 0),
plotOutput('plot'),
actionButton("go", "Go!"))
server <- function(input, output) {
# This gathers the data - I want it to stay the same unless I change input$n and click go
data <- eventReactive(input$go,
{
runif(input$n)
})
color <- eventReactive(input$go,
{
input$color
})
output$plot <- renderPlot({
hist(data(), col = color())
})
}
# Return a Shiny app object
shinyApp(ui = ui, server = server)