ShinyDashboard 侧边栏中的 ShinyTree
ShinyTree in ShinyDashboard sidebar
我有一个很好的动态生成的 shinyTree,它在 shinydashboard 的主体中显示得很漂亮。这太棒了。但是,我真正想要的是将它放在侧边栏中,以便它可以用于 select 选项卡。但是无论我怎么尝试,我似乎都无法让它出现在侧边栏中。
下面的代码无效:
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 和此处进行的搜索没有找到任何结果。
所以我是个白痴。显然你只能有一个 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)
我有一个很好的动态生成的 shinyTree,它在 shinydashboard 的主体中显示得很漂亮。这太棒了。但是,我真正想要的是将它放在侧边栏中,以便它可以用于 select 选项卡。但是无论我怎么尝试,我似乎都无法让它出现在侧边栏中。
下面的代码无效:
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 和此处进行的搜索没有找到任何结果。
所以我是个白痴。显然你只能有一个 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)