R brilhante: como incorporar sliderInputs / selectInputs e radioButtons em um quadro de dados? (Erro: não é possível coagir a classe “” shiny.tag “” para um data.frame)
Eu preciso incorporar diferentes tipos de entradas em uma matriz. Funciona bem para textInput () e numericInput (), mas não consigo encontrar uma maneira para selectInput (), sliderInput () e radioButton ().
Eu posso especificar o textInput e o numericInput em HTML, usando algo como
paste0("<input id='num", 1:2, "' class='shiny-bound-input' type='text' value=''>")
No entanto, não encontrei o caminho certo para especificar os outros tipos de entradas em HTML. Para os controles deslizantes, por exemplo, eu tentei
paste0("<input id='Sl_", 1:2, "' class='jslider shiny-bound-input' type = 'range' value='20' min='0' max='100'>")
mas o resultado não é um controle deslizante do tipo brilhante.
Então, eu tentei usar os comandos Shiny:
lapply(1:2, function(i) sliderInput(inputId = paste0("sl", i), label = "", min = 0, max =100, value = 50)).
O erro que recebo é: não é possível coagir a classe "" shiny.tag "" para um data.frame. Então deduzo que devo especificá-los em HTML -> alguém sabe como fazer isso?
Aqui está o código (e você pode ver a imagem aqui abaixo):
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))
Qualquer conselho / sugestão seria muito apreciado e obrigado antecipadamente