简体   繁体   English

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

[英]How do I use tagList() in a Shiny module?

The official tutorial by RStudio is a little unclear on how to actually use the tagList() function for creating a namespaced ID in Shiny modules. RStudio的官方教程尚不清楚如何实际使用tagList()函数在Shiny模块中创建命名空间ID。 The Shiny documentation does not help much either. Shiny文档也无济于事。 What exactly am I supposed to put inside the tagList() function? 我到底应该在tagList()函数中放什么? Should I only wrap input arguments in a tagList(), like shown in all examples and video tutorials, or can I put other elements in there, such as a sidebarPanel()? 我应该只将输入参数包装在tagList()中,如所有示例和视频教程中所示,还是可以在其中放置其他元素,例如sidebarPanel()?

tagList is nothing but creating a list of tags. tagList只是创建标签列表而已。 The definition is 定义是

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

It's a simple list having a special class shiny.tag.list . 这是一个简单的列表,具有一个特殊的类shiny.tag.list You use it when you create a module, where the UI of the module needs to return a simple page, like a fluidPage etc. If you don't want to create an extra UI for the module, you just return a few UI elements wrapped inside tagList and take care of the UI outside of the module. 在创建模块时使用它,其中模块的UI需要返回一个简单的页面,例如fluidPage等。如果您不想为该模块创建额外的UI,则只需返回包装的一些UI元素在tagList并注意模块外部的UI。 For example: 例如:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM