【问题标题】:ShinyTree in ShinyDashboard sidebarShinyDashboard 侧边栏中的 ShinyTree
【发布时间】:2021-08-09 13:53:38
【问题描述】:

我有一个很好的动态生成的 shinyTree,它在闪亮仪表板的主体中显示得很漂亮。这太棒了。但是,我真正想要的是它位于侧边栏中,因此可以用来选择一个选项卡。但无论我尝试什么,我似乎都无法让它出现在侧边栏中。

以下代码无效:

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 = "")
      )
    )
  })
})

我觉得我错过了一些非常明显的东西,但我在谷歌和这里的搜索并没有带来任何东西。

【问题讨论】:

    标签: r shiny shinydashboard shinytree shinydashboardplus


    【解决方案1】:

    所以我是个白痴。显然你只能有一个 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)
    

    【讨论】:

      猜你喜欢
      • 2021-09-28
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多