Collect all input labels in Shiny R

孤人 提交于 2021-01-03 08:38:04

问题


Inspired in this answer [Collect All user inputs throughout the Shiny App I could get all the inputs values. However, I want also the label of each shiny input.

Is there any way to get all LABELS of each input in Shiny?

Below the R-Shiny code:

library(shiny)
ui<- fluidPage(
  titlePanel("Dynamically generated user interface components"),
  fluidRow(

    column(3, 
      selectInput("cnt_id", "Country",
                  c("USA", "Cananada", "Mexico"),
                  ),
      selectInput('cod_id', 'Code', c(Choose='', c("c12","c13","c14")), selectize=FALSE),
      uiOutput("rtxt")

      ),
    column(3,
           #tags$p("Pais"),
           #verbatimTextOutput("d1"),
           #tags$p("Code"),
           #verbatimTextOutput("d2"),
           br(),
           tableOutput('show_inputs')
    )
  )
)

server <- function(input, output) {

  output$rtxt<- renderUI({
    textInput('text_id', label = 'Type comment')
  }) 


  #Get inputs
  AllInputs <- reactive({
    x <- reactiveValuesToList(input)
    data.frame(
      names = names(x),
      values = unlist(x, use.names = FALSE)
    )
  })
  #display inputs
  output$show_inputs <- renderTable({
    AllInputs()
  })

}
shinyApp(ui = ui, server = server)

The ideal output would be a table like:

+--------------+----------------+
| Input_Label  |    Input_Value |
+--------------+----------------+
| Country      |    USA         |
| Code         |    c12         |
| Type comment |  some comment  |
+--------------+----------------+

The answer can also include JavaScript, in case it's neccesary.

Thanks in advance

来源:https://stackoverflow.com/questions/54623512/collect-all-input-labels-in-shiny-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!