0

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)
firmo23
  • 7,490
  • 2
  • 38
  • 114

1 Answers1

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)
YBS
  • 19,324
  • 2
  • 9
  • 27
  • that is based on your answer https://stackoverflow.com/questions/71740038/add-a-plot-everytime-you-push-actionbutton-in-shiny-app – firmo23 Apr 04 '22 at 20:56
  • could u check that? https://stackoverflow.com/questions/73097631/dataframe-is-subseted-by-row-number-and-not-by-cell-value-after-clicking-on-dt – firmo23 Jul 24 '22 at 12:45
  • could u check this shiny issue ? https://stackoverflow.com/questions/73744699/use-the-edges-dataframe-which-is-included-inside-a-process-map-object-to-subse – firmo23 Sep 16 '22 at 14:09