'Add a choice to the radioButtons() every time the actionButton() is pressed
In the shiny app below I would like every time I press the actionButton() to be added a choice to the radioButtons() like "Plot 2", "Plot 3" etc.
## app.R ##
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
actionButton("add","Add choice"),
uiOutput("sil1")
),
dashboardBody(
)
)
server <- function(session,input, output) {
output$sil1<-renderUI({
radioButtons("pp","Pick plot",choices =c("Plot 1"))
})
}
shinyApp(ui, server)
Solution 1:[1]
Perhaps you are looking for this
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
actionButton("add","Add choice"),
radioButtons("pp","Pick plot",choices = c("Plot 1"))
),
dashboardBody(
)
)
server <- function(input, output, session) {
my <- reactiveValues(choices="Plot 1")
observeEvent(input$add, {
my$choices <- c(my$choices,paste("Plot",input$add+1))
updateRadioButtons(session,"pp",choices=my$choices)
})
}
shinyApp(ui, server)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | YBS |
