首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ShinyDashboard侧边栏中的ShinyTree

ShinyDashboard侧边栏中的ShinyTree
EN

Stack Overflow用户
提问于 2021-05-20 18:02:43
回答 1查看 37关注 0票数 0

我有一个很好的动态生成的shinyTree,它在shinydashboard的主体中显示得很漂亮。这太棒了。然而,我真正想要的是让它出现在侧边栏中,这样它就可以用来选择一个选项卡。但是无论我怎么尝试,我似乎都不能让它出现在侧边栏中。

以下代码不起作用:

代码语言:javascript
复制
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上的搜索没有找到任何东西。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-22 19:13:12

所以我是个笨蛋。显然,您只能有一个shinyTree实例,所以主体中的shihyTree阻止了侧边栏中的shinyTree显示。

工作代码如下:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67618198

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档