如何在Shiny模块中使用tagList()?

时间:2016-12-20 11:21:48

标签: r shiny

官方tutorial by RStudio对如何实际使用tagList()函数在Shiny模块中创建命名空间ID有点不清楚。 Shiny documentation也没有多大帮助。究竟我应该把它放在tagList()函数中?我应该只在tagList()中包装输入参数,如所有示例和视频教程中所示,或者我可以在其中放置其他元素,例如sidebarPanel()?

1 个答案:

答案 0 :(得分:2)

tagList只是创建一个标签列表。定义是

> tagList
function (...) 
{
    lst <- list(...)
    class(lst) <- c("shiny.tag.list", "list")
    return(lst)
}

这是一个包含特殊班级shiny.tag.list的简单列表。您在创建模块时使用它,模块的UI需要返回一个简单的页面,如fluidPage等。如果您不想为模块创建额外的UI,您只需返回包含在tagList内的一些UI元素,并处理模块外部的UI。例如:

library(shiny)

moduleUI <- function(id){
    ns <- NS(id)

    # return a list of tags
    tagList(h4("Select something"),
            selectInput(ns("select"), "Select here", choices=1:10))
  }

module <- function(input, output, session){}

ui <- shinyUI(
  fluidPage(wellPanel(moduleUI("module"))) # wrap everything that comes from the moduleUI in a wellPanel
)

server <- shinyServer(function(input, output, session){
  callModule(module, "module")
})

shinyApp(ui = ui, server = server)
相关问题