4

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

  • Looks like you have it working. Its unclear what you need, do you want the same functionality with no server side code? – Sada93 Feb 11 '19 at 04:34
  • @Sada93 in the app, the table `show_inputs` only shows the `id` of the input and the `value` of the input, But not the `label` of the input (which are `Country`, `Options`, `Type comment`). – Omar Benites Feb 11 '19 at 05:07

0 Answers0