r - Shiny: add button label to sidebar & update buttons after click -


i'm bit rusty shiny reactivity, want 2 things when button clicked:

  1. add button label sidebar (and add more labels sidebar after more clicks)
  2. update button labels (i.e. more random integers)

i'm nervous changing label before recording it, want timing right. here's skeleton of i'm working with:

library(shiny)  ui <- fluidpage(   sidebarlayout(     sidebarpanel(        textoutput("clicks")     ),     mainpanel(       uioutput("button1"),        uioutput("button2")     )) ) ################### server <- function(input, output, session) {    output$clicks <- rendertext({     paste()   })    ## reactive values   inside <- reactive({     inside <- sample(1:100,2)   })    ## buttons   output$button1 <- renderui({     actionbutton("course1", label = inside()[1], style='padding:50px')   })   output$button2 <- renderui({     actionbutton("course2", label = inside()[2], style='padding:50px')   }) }  shinyapp(ui = ui, server = server) 

right sidebar blank because i'm not sure how add it, or add make button labels update after click (whether inside reactive value or observeevent). appreciated!

here's way reactivevalues:

library(shiny)  ui <- fluidpage(   sidebarlayout(     sidebarpanel(        textoutput("clicks")     ),     mainpanel(       uioutput("button1"),        uioutput("button2")     )) ) ################### server <- function(input, output, session) {   # show history   output$clicks <- rendertext({     history[['clicked']]   })    ## reactive values   # store history reactive values   history <- reactivevalues(clicked = c())   # update history when button clicked   observeevent(input$course1,{     history[['clicked']] <- c(history[['clicked']],inside()[1])   })    observeevent(input$course2,{     history[['clicked']] <- c(history[['clicked']],inside()[2])   })   #update inside when history updates   inside <- reactive({     history[['clicked']]     inside <- sample(1:100,2)   })    ## buttons   output$button1 <- renderui({     actionbutton("course1", label = inside()[1], style='padding:50px')   })   output$button2 <- renderui({     actionbutton("course2", label = inside()[2], style='padding:50px')   }) }  shinyapp(ui = ui, server = server) 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -