r - Update two sets of radiobuttons reactively - shiny -
i have read (how make choices in radiobuttons reactive in shiny?) shows me how update radiobutton
s in reactive way. however, when try , update 2 sets of buttons same data, 1 set renders. example:
server:
# create example data wafer <- rep(c(1:3), each=3) length <- c(1,1,2,1,1,1,3,5,1) width <- c(3,1,6,1,1,1,1,1,6) dd <- data.frame(wafer, length, width) shinyserver(function(input, output, session){ # create reactive dataframe store data values <- reactivevalues() values$df <- data.frame() # lengths , widths of wafer user input <- eventreactive(input$do, { subset(dd, wafer %in% input$wafer, select = length:width) }) # update reactive data frame lengths , widths have been selected user input observe({ if(!is.null(a())) { values$df <- rbind(isolate(values$df), a()) } }) output$wl <- renderdatatable({ a() }) # update radio buttons unique length , widths stored in values$df # ever "observe" put first in code, 1 updates # radio buttons. cut , paste other way round , "width" # updates not "length" radio buttons observe({ z <- values$df updateradiobuttons(session, "length", choices = unique(z$length), inline=true) }) observe({ z <- values$df updateradiobuttons(session, "width", choices = unique(z$width), inline=true) }) })
ui:
library(markdown) shinyui(fluidpage( titlepanel("generic grapher"), sidebarlayout( sidebarpanel( numericinput("wafer", label = h3("input wafer id:"), value = null), actionbutton("do", "search wafer"), radiobuttons("length", label="length", choices=""), radiobuttons("width", label="width", choices = "") ), mainpanel( datatableoutput(outputid="wl") ) ) ) )
in above, radiobuttons update first set of buttons in order of code i.e. above "length" updates "width" doesn't. if write them in reverse, "width" updates "length" doesn't. need define new session maybe?
it turns out that:
"it's because js error occurs if choices argument isn't character vector."
i have posted issue on shiny's github:
https://github.com/rstudio/shiny/issues/1093
this can resolved by:
to fix problem, can either convert choices characters using as.character or set selected random string such "".
see:
Comments
Post a Comment