Can you create a shinyTree in r with checkbox but only the children have checkboxes?

484 Views Asked by At

Is it possible to have only the lowest level children in a shinyTree have a checkbox? In the below screenshot I would like 'Recreational -Fishing' and 'Boat' to not have a checkbox but all the other children to have a checkbox (in screenshot; circles = checkboz, + = no checkbox)?

Thanks!

library(shiny)
library(shinyTree)

# Create tree data ----
tree.data <-    list(
  'Recreational - Fishing' = structure(list(
    'Boat' = structure(list(
      'Cray pot'= structure("",sttype="default",sticon="glyphicon glyphicon-record"),
      'Hand/rod & line' = structure("",sttype="default",sticon="glyphicon glyphicon-record"),
      'Cray loop' = structure("",sttype="default",sticon="glyphicon glyphicon-record"),
      'Drop net' = structure("",sttype="default",sticon="glyphicon glyphicon-record"),
      'Spear' = structure("",sttype="default",sticon="glyphicon glyphicon-record"),
      'Other' = structure("",sttype="default",sticon="glyphicon glyphicon-record")),
      sttype="default",stopened=FALSE,sticon="glyphicon glyphicon-plus", stdisabled=TRUE)),
    sttype="default",stopened=FALSE,sticon="glyphicon glyphicon-plus")
  )

# UI ----
ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
          shinyTree("tree", checkbox = TRUE, search=TRUE, searchtime = 1000)
        ),

        # Show a plot of the generated distribution
        mainPanel(
           
        )
    )
)

#Server ----
server <- function(input, output) {

  # Render Tree
  output$tree <- renderTree({
    tree.data
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

screenshot

3

There are 3 best solutions below

0
On BEST ANSWER

add to your css:

.jstree li.jstree-open > a.jstree-anchor > i.jstree-checkbox,
.jstree li.jstree-closed > a.jstree-anchor > i.jstree-checkbox {
   display:none; 
}
8
On

You can add the following css to your shiny app to hide some checkboxes in shinyTree:

#\31 _anchor > .jstree-checkbox {
    display: none;
}

#\32 _anchor > .jstree-checkbox {
    display: none;
}

enter image description here

0
On

In my case I only wanted to disable the checkbox at the top level so my ui looks like:

ui <- fluidPage(
    tags$head(
        tags$style(
            HTML("
            div.jstree > ul.jstree-children > li > a.jstree-anchor > i.jstree-checkbox {
                display:none; 
            }")
        )
    ),
    .
    .
    .