Does someone know how to make actionButton (R shiny) reset to initial value in order to use it more than once?
Please find below a reproductible example:
In this example, I would like to change the chart color by selecting the corresponding button: my issue is that it cannot reload the chart after one iteration.
library(shiny)
ui <- fluidPage(
actionButton(inputId = "button1",label = "Select red"),
actionButton(inputId = "button2",label = "Select blue"),
plotOutput("distPlot")
)
server <- function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x))
my_color <- "green"
if (input$button1){my_color <- "red"}
if (input$button2){my_color <- "blue"}
hist(x, breaks = bins, col = my_color)
})
}
shinyApp(ui = ui, server = server)
Thank you in advance
observeEvent
? and aifelse
orcase_when
function? like:observeEvent(c(input$button1, input$button2){ r$my_color <- case_when(input$button1 > 0 ~ "red", input$button2 > 0 ~ "blue" })
I can't really get something like this to work. – Radarman