对复选框的限制只选择父节点而不是子节点,就像简单选择R中的shinyTree节点一样

时间:2017-02-03 11:18:39

标签: javascript r 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)

在运行上面的代码时,在选择sublistB时,它的子代也会被选中。

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

我怎样才能选择subListB,而不选择它的叶子。就像我们使用shinyTree的简单select属性时会发生什么。

library(shiny)
library(shinyTree)
server <- shinyServer(function(input, output, session) {
  output$tree <- renderTree({
    list(
      root1 = "",
      root2 = list(
        SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListB = list(leafA = "", leafB = "")
      )
    )
  })
})
ui<-shinyUI(
  pageWithSidebar(
    # Application title
    headerPanel("Simple shinyTree!"),
     sidebarPanel(
    mainPanel(
      # Show a simple table.
      shinyTree("tree")
    )
  ))
shinyApp(ui, server) 

Simple shinyTree selection of only parent node SubListB and not the child nodes leafA and leafB

0 个答案:

没有答案