[英]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:这是尽可能精简的应用程序:
library(shiny)
library(shinydashboard)
source("modules.r")
ui <- dashboardPage(
dashboardHeader(
title = "Shiny modules and shinydashboard"
),
dashboardSidebar(
sidebarMenu(
menuItem("PointA")
)
),
dashboardBody(
tabItems(
fooUI("myid")
)
)
)
server <- function(input, output) {
callModule(foo, "myid")
}
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
.我正在使用最新版本的
R
, shiny
和shiny
shinydashboard
。 This is not the issue here.这不是这里的问题。
Problem with shinydashboard
and tagList
shinydashboard
和tagList
问题
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" )
)
)
You also need tabName
in menuItem
您还需要在
menuItem
tabName
menuItem("PointA_",tabName = "PointA")
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
然后你可以使用
tabItems1
和tagList
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:两件事:
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.