R中reactiveValuesToList()函数的奇怪行为
我最近发现了R中reactiveValuesToList()函数的奇怪行为,r,shiny,reactive-programming,R,Shiny,Reactive Programming,我最近发现了reactiveValuesToList()函数,我用它跟踪应用程序中的输入,因为有些输入是动态创建的。下面是一个简单的例子来说明函数的奇怪行为 我的应用程序有3个组件: checkBoxGroupInput():有3个选项 uiOutput():根据用户选中的框动态创建数字输入 textOutput():显示web应用程序中所有输入UI的ID 以下是上述简单应用程序的脚本: library(shiny) ui <- fluidPage( # The user se
reactiveValuesToList()
函数,我用它跟踪应用程序中的输入,因为有些输入是动态创建的。下面是一个简单的例子来说明函数的奇怪行为
我的应用程序有3个组件:
:有3个选项checkBoxGroupInput()
:根据用户选中的框动态创建数字输入uiOutput()
:显示web应用程序中所有输入UI的IDtextOutput()
library(shiny)
ui <- fluidPage(
# The user selects team names
checkboxGroupInput(inputId = "team", label = "Select team", choices = letters[1:3]),
br(),
# Placeholder for the dynamic numeric inputs that are created based on the selected team names
uiOutput(outputId = "dynUI1"),
# Text output for the names of the input UIs in the shiny app
textOutput(outputId = "uiIds")
)
server <- function(input, output){
# These are the input IDs of the dynamically created UI in dynUI1
uiNames <- c(a = "id_a", b = "id_b", c = "id_c")
output$dynUI1 <- renderUI({
if(length(input$team) == 0){
return(NULL)
} else {
lapply(1:length(input$team), function(i){
inputname <- paste0("Points: team ", input$team[i])
numericInput(inputId = uiNames[input$team[i]], label = inputname, value = 1, min = 1, max = 5)
})
}
})
output$uiIds <- renderText({
names(reactiveValuesToList(input))
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
ui您是否尝试过使用闪亮0.14中的insertUI
和removeUI
来创建动态ui?如果是的话,这能解决问题吗?@warmoverflow,我没有。我会尝试一下,让你知道。谢谢。您是否尝试过使用闪亮0.14中的insertUI
和removeUI
来创建动态UI?如果是的话,这能解决问题吗?@warmoverflow,我没有。我会尝试一下,让你知道。非常感谢。