我有一个很好的动态生成的shinyTree,它在shinydashboard的主体中显示得很漂亮。这太棒了。然而,我真正想要的是让它出现在侧边栏中,这样它就可以用来选择一个选项卡。但是无论我怎么尝试,我似乎都不能让它出现在侧边栏中。
以下代码不起作用:
library(shiny)
library(shinyTree)
library(shinydashboard)
library(shinydashboardPlus)
header <- dashboardHeader(title = "MWE")
body <- dashboardBody(
# works fine in the body
shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE)
)
sidebar <- dashboardSidebar(
# doesn't work here
# shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE)
sidebarMenu(
# doesn't work here
# shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE)
menuItem("test"
# or here
# shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE)
)
)
)
shinyUI(
dashboardPage(
header = header,
sidebar = sidebar,
body = body
)
)
shinyServer(function(input, output, session) {
# Simplified test tree
output$tree <- renderTree({
list(
root1 = "",
root2 = list(
SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
SubListB = list(leafA = "", leafB = "")
),
root3 = list(
SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
SubListB = list(leafA = "", leafB = "")
)
)
})
})我觉得我漏掉了一些很明显的东西,但我在google和here上的搜索没有找到任何东西。
发布于 2021-05-22 19:13:12
所以我是个笨蛋。显然,您只能有一个shinyTree实例,所以主体中的shihyTree阻止了侧边栏中的shinyTree显示。
工作代码如下:
library(shiny)
library(shinyTree)
library(shinydashboard)
library(shinydashboardPlus)
header <- dashboardHeader(title = "MWE")
body <- dashboardBody(
# Don't put the shinyTree in the body!
# shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE)
)
sidebar <- dashboardSidebar(
#shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE),
sidebarMenu(
shinyTree("tree", stripes = TRUE, multiple = FALSE, animation = FALSE)
)
)
ui <- dashboardPage(
header = header,
sidebar = sidebar,
body = body
)
server <- function(input, output, session) {
# Simplified test tree
output$tree <- renderTree({
list(
root1 = "",
root2 = list(
SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
SubListB = list(leafA = "", leafB = "")
),
root3 = list(
SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
SubListB = list(leafA = "", leafB = "")
)
)
})
}
shinyApp(ui, server)https://stackoverflow.com/questions/67618198
复制相似问题