受到这个答案的启发[Collect All user inputs throughout the Shiny App我可以获得所有输入值。但是,我还需要每个闪亮输入的标签。
有没有办法在Shiny中获取每个输入的所有标签?
R-Shiny代码下方:
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)
理想的输出应该是像这样的表:
+--------------+----------------+
| Input_Label | Input_Value |
+--------------+----------------+
| Country | USA |
| Code | c12 |
| Type comment | some comment |
+--------------+----------------+
答案是JavaScript
,以备不时之需。
预先感谢