简体   繁体   English

使用闪亮的模块和闪亮的仪表板:shiny.tag 错误

[英]Using shiny modules and shinydashboard: shiny.tag error

I'm trying to create and use shiny modules inside a shinydashboard app but I keep getting this error:我正在尝试在 Shinydashboard 应用程序中创建和使用闪亮的模块,但我不断收到此错误:

Error in FUN(X[[i]], ...) : Expected an object with class 'shiny.tag'.

Here is the app as condensed as possible:这是尽可能精简的应用程序:

ui.r用户界面

library(shiny)
library(shinydashboard)

source("modules.r")

ui <- dashboardPage(
 dashboardHeader(
  title = "Shiny modules and shinydashboard"
 ),

 dashboardSidebar(
  sidebarMenu(
   menuItem("PointA") 
  )
 ),

 dashboardBody(
  tabItems(
   fooUI("myid") 
  )
 )
)

server.r服务器文件

server <- function(input, output) {
 callModule(foo, "myid") 
}

modules.r模块.r

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

 tagList(
  tabItem(
   tabName = "PointA",
   textOutput(ns("text"))
  )
 )
}

foo <- function(input, output, session){

 output$text <- renderText(
  rnorm(1)
 )
}

What am I doing wrong?我做错了什么? I got other kinds of modules to work in a "normal" shiny app, however, whenever I try to use a module within shinydashboard it fails.我让其他类型的模块在“普通”闪亮的应用程序中工作,但是,每当我尝试在 Shinydashboard 中使用模块时,它都会失败。

I am using the newest version of R , shiny and shinydashboard .我正在使用最新版本的Rshinyshiny shinydashboard This is not the issue here.这不是这里的问题。

Problem with shinydashboard and tagList shinydashboardtagList问题

As described here如上所述这里

You need simple use你需要简单的使用

   ui <- dashboardPage(
  dashboardHeader(
    title = "Shiny modules and shinydashboard"
  ),

  dashboardSidebar(
    sidebarMenu(
      menuItem("PointA",tabName = "PointA") 
    )
  ),

  dashboardBody(
    tags$div( fooUI("myid"), class = "tab-content" )

)
)

Update更新

You also need tabName in menuItem您还需要在menuItem tabName

menuItem("PointA_",tabName = "PointA") 

Explanation说明

As you can see如你所见

tabItems
function (...) 
{
    lapply(list(...), tagAssert, class = "tab-pane")
    div(class = "tab-content", ...)
}
<environment: namespace:shinydashboard>

use list to ... and cant work if you already have list as arg.使用list...并且如果您已经将 list 作为 arg 则无法工作。

So other variant it create new tabItems function like所以其他变体它创建新的 tabItems 功能,如

tabItems1=function (...) 
    {
        lapply(..., tagAssert, class = "tab-pane")
        div(class = "tab-content", ...)
    }
environment(tabItems1)=environment(tabItems)

And then you can use tabItems1 with tagList然后你可以使用tabItems1tagList

Following @Batanichek's answer which pointed me to the source of the problem (thanks for that) I simply removed the tagList() command in my fooUI definition.按照@Batanichek 的回答,我指出了问题的根源(谢谢),我只是删除了fooUI定义中的tagList()命令。 This conveniently solves the problem!这样很方便的解决了问题!

Two things:两件事:

  1. Seems tabName is necessary in the menuItem function在 menuItem 函数中似乎需要 tabName
  2. Move tabItem from the module to ui (tabItem can hold you module)将 tabItem 从模块移动到 ui(tabItem 可以容纳你的模块)

UI用户界面

ui <- dashboardPage(
  dashboardHeader(
    title = "Shiny modules and shinydashboard"
  ),

  dashboardSidebar(
    sidebarMenu(
      menuItem("PointA", tabName = "PointA") 
    )
  ),

  dashboardBody(
    tabItems(
      tabItem("PointA",
              fooUI("myid")
      )
    )
  )
)

Module模块

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

  tagList(
    tabName = "PointA",
    textOutput(ns("text"))
  )
}

foo <- function(input, output, session){

  output$text <- renderText(
    rnorm(1)
  )
}

暂无
暂无

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

相关问题 Shinydashboard 错误消息“预期具有类 &#39;shiny.tag 的对象” - shinydashboard error message "Expected an object with class 'shiny.tag" 编辑一个 Shiny.tag 元素 - Edit a shiny.tag element 错误:在渲染 ValueBox 时需要一个类为“shiny.tag”的对象 - Error: Expected an object with class 'shiny.tag' while rendering ValueBox 使用流图生成 htmlwidget 而不是 Shiny.tag - Generating a htmlwidget instead of a Shiny.tag with streamgraph 错误:尝试输出 renderValueBox 时,需要类为“shiny.tag”的对象 - Error: Expected an object with class 'shiny.tag' when trying to output renderValueBox R Shiny:如何在数据框中嵌入sliderInputs / selectInputs和radioButtons? (错误:无法将类“” shiny.tag””强制转换为data.frame) - R shiny: how to embed sliderInputs/selectInputs and radioButtons in a data frame ? (Error: cannot coerce class “”shiny.tag“” to a data.frame) 将Shiny.tag对象(发光的输入对象)转换为html对象或字符对象 - Convert shiny.tag object (shiny input object) to html object or character object RStudio Shiny ERROR:没有名为“shinydashboard”的软件包 - RStudio Shiny ERROR: there is no package called “shinydashboard” 使用闪亮模块时,如何在闪亮仪表板中动态发布通知 - How can I dynamically post notifications in shinydashboard when using shiny modules R Shiny:如何使用Shinydashboard库在Shiny应用程序中显示数据框 - R Shiny: how to display dataframe in shiny app using shinydashboard library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM