如何限制shinyTree R中的单个复选框选择

时间:2017-02-02 12:53:08

标签: r shinyjs shinytree

我正在使用shinyTree包及其复选框选项。

   library(shiny)
    library(shinyTree)

    server <- shinyServer(function(input, output, session) {
      # Defining lists inside list and rendering it in the shinyTree
      output$tree <- renderTree({
        list(
          root1 = "123",
          root2 = list(
            SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
            SubListB = structure(list(leafA = "", leafB = ""),stselected=TRUE)
          )
        )
      })
    })

    ui <- shinyUI(
      pageWithSidebar(
        # Application title
        headerPanel("shinyTree with checkbox controls"),
        sidebarPanel(
         mainPanel(
          # Show a simple table with checkbox.
          shinyTree("tree", checkbox = TRUE)
      ))
    )

shinyApp(ui, server)

在运行上面的代码时,在选择子列表B时,它的子节点也会被选中。

SublistB was selected but the child leafA and leafB also are selected

我怎样才能选择subListB,而不选择它的叶子。

1 个答案:

答案 0 :(得分:0)

我不知道直接的方式,但作为计划B,您可以拥有此节点的特定孩子。您将给出一个代表其父级的名称,您可以选择而不选择其他children/leaf

SubListA = list(leafSLA = "SubListA", leaf1 = "", leaf2 = "", leaf3=""),
SubListB = structure(list(leafSLB = "SubListB", leafA = "", leafB = ""),stselected=TRUE)