有人知道如何将 actionButton (R shiny) 重置为初始值以便多次使用它吗?
请在下面找到一个可复制的示例:
在此示例中,我想通过选择相应的按钮来更改图表颜色:我的问题是它无法在一次迭代后重新加载图表。
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)
先感谢您