How to restrict a single selection of checkbox in shinyTree R

426 Views Asked by At

I am using shinyTree package and its checkbox option.

   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)

While running the above code, while selecting the sublistB the child of it also gets selected.

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

How can I only select subListB, and not selecting its leaves.

1

There are 1 best solutions below

0
On

I don't know a direct way, but as a plan B you could have a specific child of this node. You would give a name that would represent its parent, that you could select without selecting other children/leaf.

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