How to observe individual input elements which were created in bulk in R Shiny -
i have set of sliderinput
s number equals number of columns in data. number of columns determined values of choices
global.r
. each slider associate 1 column , created shown bellow in server.r
, ui.r
.
i observe
them individually can apply values associated column. in example. suggestion?
#example. not valide code!!! selectedvalbysliders <- observe({ print("numbers selected via sliders:") out_sliders <- input$sliders[1:numsliders] print(out_sliders) })
server.r
output$sliders <- renderui({ numsliders <- numcols(input$dataname) lapply(1:numsliders, function(i) { sliderinput( inputid = paste0('column', i), label = paste0('select range column ', i), min = min(selectrange(input$dataname)), max = max(selectrange(input$dataname)), value = c(min(selectrange(input$dataname)), max(selectrange(input$dataname))), step =1) }) })
ui.r
uioutput(outputid = "sliders"),
global.r
selectrange <- function(x){ if(x == "data1"){choices = c(1:10)} if(x == "data2"){choices = c(1:15)} if(x == "data3"){choices = c(1:20)} if(x == "data4"){choices = c(1:25)} return(choices) } numcols <- function(x){ if(x == "data1"){ncolumns = 4} if(x == "data2"){ncolumns = 5} if(x == "data3"){ncolumns = 5} if(x == "data4"){ncolumns = 6} return(ncolumns) }
in case might bump same issue, here solution. feel free update better answer if have one.
minmax <- matrix(0, ncol(getdata), 2) for(i in seq(ncol(getdata))){ if(!is.null(input[[paste0('column', i)]])){ val <- input[[paste0('column', i)]] minmax[i,] <- val index <- which(getdata[, i] %in% c(minmax[i, 1]:minmax[i, 2])) selectedset <- getdata[index, ] } }