我目前在使我的模块 UI 和服务器与创建布局的中间 renderUI 通信时遇到问题。这是一个有和没有动态创建 tabsetPanel 的代表。我猜这个问题来自命名空间,但我不知道在哪里以及如何解决它。不工作 :
mod_graphical_general_ui <- function(id){
ns <- NS(id)
tagList(
selectInput(ns("myselect"), "Select a choice", choices = NULL)
)}
mod_graphical_general_server <- function(id, choices = NULL) {
moduleServer( id, function(input, output, session){
ns <- session$ns
updateSelectInput(session, "myselect", choices = choices)
})
}
ui <- bootstrapPage(
uiOutput("mytabs")
)
server <- function(input, output) {
mod_graphical_general_server("mymodule", choices = c("aaa", "bbb"))
output$mytabs = renderUI({
number_of_tabs <- 3
names_tab <- paste0("Tab", 1:number_of_tabs)
myTabs = lapply(1: number_of_tabs, function(x) {tabPanel(names_tab[[x]], div(uiOutput(paste0("graphics_tab", x))))})
do.call(tabsetPanel, c(myTabs))
})
output$graphics_tab1 <- renderUI({
return(mod_graphical_general_ui("mymodule"))
})
}
shinyApp(ui = ui, server = server)
如果我从调用 tabsetPanel 中删除该步骤,则代码有效。
mod_graphical_general_ui <- function(id){
ns <- NS(id)
tagList(
selectInput(ns("myselect"), "Select a choice", choices = NULL)
)}
mod_graphical_general_server <- function(id, choices = NULL) {
moduleServer( id, function(input, output, session){
ns <- session$ns
updateSelectInput(session, "myselect", choices = choices)
})
}
ui <- bootstrapPage(
#uiOutput("mytabs")
uiOutput("graphics_tab1")
)
server <- function(input, output) {
mod_graphical_general_server("mymodule", choices = c("aaa", "bbb"))
output$mytabs = renderUI({
number_of_tabs <- 3
names_tab <- paste0("Tab", 1:number_of_tabs)
myTabs = lapply(1: number_of_tabs, function(x) {tabPanel(names_tab[[x]], div(uiOutput(paste0("graphics_tab", x))))})
do.call(tabsetPanel, c(myTabs))
})
output$graphics_tab1 <- renderUI({
return(mod_graphical_general_ui("mymodule"))
})
}
shinyApp(ui = ui, server = server)
我已经在社区 rstudio 中问过这个问题,但没有运气。