如果面板被打开另一个面板折叠,Shinytree渲染消失

rn0zuynd  于 2023-10-13  发布在  其他
关注(0)|答案(1)|浏览(81)

我正试图为我的工作场所建立一个shinydashboard,以创建一个可搜索的表格,显示在我们不同的分支机构中谁擅长做什么。
我想有两个侧边栏项目,过滤表的位置,或技术。位置将是一棵树(国家/城市/名称),技术是一组按钮。
我的问题是当我从一个标签跳到另一个。如果我在跳转到技术选项卡之前关闭位置选项卡(或相反),一切都很好,但如果我打开技术选项卡而不关闭位置,树就会消失,我无法恢复。
类似于我的其他职位在这里我试图检查页面,我可以看到,线<ul class="jstree-container-ul jstree-children jstree-no-icons jstree-striped" role="group"> gets a new argument style="display: none;"一旦另一个面板打开,这将不会被覆盖,当我重新打开面板.在文本栏中键入一些内容确实会将显示恢复为阻止,但我不知道如何强制显示:当我点击面板时,我试着使用与其他帖子相同的技巧,但我找不到如何将其应用于shinytree。
js <- " $(document).ready(function() { $('a[href=\"#shiny-tab-location\"').on('click', function() { $('.treejs-nodes').css('display', 'block'); }); }) "
我的代码复制:

library(shiny)
library(shinyTree)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(title = "Filters"),
  dashboardSidebar(
    # Increase the width of the sidebar panel
    useShinyjs(),
    sidebarMenu(
      menuItem("By Location", tabName = "location", icon = icon("earth-europe"),
               div(
                 style = "max-height: 42vh; overflow-y: auto; overflow-x: auto;",  # Set the maximum height and provide a scrollbar
                 shinyTree("tree", stripes = TRUE, multiple = TRUE, animation = TRUE, checkbox = TRUE, search=TRUE, themeIcons = FALSE)
               )
               
      ),
      
      menuItem("By Technique", tabName = "technique", icon = icon("microscope"),
               fluidRow(
                 # Adjust column sizing and spacing
                 column(3, actionBttn(inputId = "group1_btn", label = "Btn1", style = "jelly", color = "danger")),
                 column(3, actionBttn(inputId = "group2_btn", label = "Btn1", style = "jelly", color = "danger")),
                 column(3, actionBttn(inputId = "group3_btn", label = "Btn1", style = "jelly", color = "danger"))
                 
               ),
               
               # Technique checkboxes will be displayed here in the body
               uiOutput("technique_checkboxes")
               
    ))),
  dashboardBody(
    DTOutput("table")
  ))

server <- function(input, output, session) {
  output$tree <- renderTree({
    list(
      root1 = list(
        SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListAB = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListAC = list(leaf1 = "", leaf2 = "", leaf3="")
      ),
      root2 = list(
        SubListB = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListBA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListBC = list(leafA = "", leafB = "")
      )
    )
  })
}

shinyApp(ui,server)
uurity8g

uurity8g1#

问题已在Github上解决
我不知道为什么这仍然隐藏,但以下为我解决了这个问题:
observeEvent(input$sidebarItemExpanded, { runjs("$('#tree > ul').css('display', 'block');") })

相关问题