我有一个闪亮的UI,我无法弄清楚如何让React文本框出现所需的信息,然后保存到全球环境。下面是我的代码和图片,以协助我试图实现。
#shiny application
library(shiny)
words <- c("age", "gender", "income", "education")
ui <- fluidPage(
titlePanel("Custom Raking"),
mainPanel(
column(5,
h3("Test"),
lapply(words, function(x){
selectInput(inputId = paste0('test_',x), label = x,
choices = c("user-entered", "to-total", "to-control", "to-test"),
selected = "to-total")})
),
column(5,
h3("Control"),
lapply(words, function(y){
selectInput(inputId = paste0('control_',y), label = y,
choices = c("user-entered", "to-total", "to-control", "to-test"),
selected = "to-total")})
)
)
)
server <- function(input, output) {
observe({
choices_x <- lapply(words, function(x){
input[[paste0('test_',x)]]})
# Assign the list of choices to the global environment
assign("choices_x", choices_x, envir = .GlobalEnv)
})
observe({
choices_y <- lapply(words, function(y){
input[[paste0('control_',y)]]})
assign("choices_y", choices_y, envir = .GlobalEnv)
})
}
# Run the application
shinyApp(ui = ui, server = server,options=c(launch.browser = .rs.invokeShinyPaneViewer))
以下是当前UI的样子:
如果选择“用户输入”,我希望它有一个额外的框供用户输入信息,如下所示:
1条答案
按热度按时间1zmg4dgp1#
一种选择是使用
conditionalPanel
添加textInput