I need to embed different types of Inputs in a matrix. It works fine for textInput() and numericInput(), but I can't find a way for selectInput(), sliderInput() and radioButton().
I can specify the textInput and the numericInput in HTML, using something like
paste0("<input id='num", 1:2, "' class='shiny-bound-input' type='text' value=''>")
However I did not find the right way to specify the other types of inputs in HTML. For the sliders for example, I've tried
paste0("<input id='Sl_", 1:2, "' class='jslider shiny-bound-input' type = 'range' value='20' min='0' max='100'>")
but the result is not a shiny-type slider.
So I tried to use the Shiny commands:
lapply(1:2, function(i) sliderInput(inputId = paste0("sl", i), label = "", min = 0, max =100, value = 50)).
The Error that I get is: cannot coerce class ""shiny.tag"" to a data.frame. So I deduct that I should specify them in HTML -> does somebody know how to do this ?
Here is the code (and you can see the picture here below):
ui = pageWithSidebar( headerPanel("TEST"), sidebarPanel( helpText('Some types of input can be included in a matrix and some do not') ), mainPanel( uiOutput('matrix_text'), uiOutput('matrix_num'), uiOutput('matrix_slider'), uiOutput('matrix_select'), uiOutput('matrix_radioButtons') ) ) server = function(input,output){ output$matrix_text <- renderTable({ matrix_input <- paste0("<input id='num", 1:2, "' class='shiny-bound-input' type='text' value=''>") matrix <- data.frame(matrix_input) row.names(matrix) <- c("r 1","r 2") colnames(matrix) <- c('C 1') matrix },sanitize.text.function = function(x) x) output$matrix_num <- renderTable({ matrix_input <- paste0("<input id='num", 1:2, "' class='shiny-bound-input' type='number' value=''>") matrix <- data.frame(matrix_input) row.names(matrix) <- c("r 1","r 2") colnames(matrix) <- c('C 1') matrix },sanitize.text.function = function(x) x) output$matrix_slider <- renderTable({ matrix_input <- lapply(1:2, function(i) sliderInput(inputId = paste0("sl", i), label = "", min = 0, max =100, value = 50)) matrix <- data.frame(matrix_input) },sanitize.text.function = function(x) x) output$matrix_select <- renderTable({ matrix_input <- lapply(1:2, function(i) selectInput(inputId = paste0("select", i), label = "", choices = c("Cylinders" = "cyl","Transmission" = "am"))) matrix <- data.frame(matrix_input) },sanitize.text.function = function(x) x) output$matrix_radioButtons <- renderTable({ matrix_input <- lapply(1:2, function(i) radioButtons(inputId = paste0("radio", i), label = "",choices= c("Cylinders" = "cyl","Transmission" = "am"), selected = NULL)) matrix <- data.frame(matrix_input) },sanitize.text.function = function(x) x) } runApp(list(ui = ui, server = server))
Any advice/suggestion would be highly appreciated and thanks in advance Cheers
