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

0

Issue

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

Solution

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; 
}

Answered By – Brooke Gibbons

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More