【问题标题】:How do I use tagList() in a Shiny module?如何在 Shiny 模块中使用 tagList()?
【发布时间】:2021-08-03 18:21:16
【问题描述】:

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

【问题讨论】:

  • 您能否参考文档并提供您想要实现的代码示例?
  • 描述现在更新为文档链接。我的目标是了解如何在创建 Shiny 模块时正确使用 tagList() 函数。
  • 如果 R-Studio 不会,没有人能给你一个权威的答案。最好是尝试一下,看看它插入的位置。可以在R-Studio html预览功能中很好的查看html,或者打开浏览器使用Chrome html调试器。
  • 如果你想引起代码作者的注意(运气好的话),你也可以在 Google Groups 的 Shiny 讨论列表上提问。
  • 感谢大家抽出宝贵时间回复。

标签: r shiny


【解决方案1】:

tagList() 只创建一个简单的标签列表。定义是

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

这是一个简单的列表,有一个特殊的类shiny.tag.list。在创建模块时使用它,模块的 UI 需要返回一个简单的页面,例如 fluidPage 等。如果您不想为模块创建额外的 UI,则只需返回几个 UI包裹在 tagList 内的元素,并负责模块外部的 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-16
    • 2018-05-05
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多