Search code examples
rshinyshinytree

shinyTree: view without selecting


Consider the following:

library(shiny)
library(shinyTree)
server <- shinyServer(function(input, output, session) {  
  output$tree <- renderTree({ 
    list(  'I lorem impsum'= list( 
      'I.1 lorem impsum'   =  structure(list('I.1.1 lorem impsum'='1', 'I.1.2 lorem impsum'='2'),stselected=TRUE),  
      'I.2 lorem impsum'   =  structure(list('I.2.1 lorem impsum'='3'), stselected=TRUE))) 
  })
})
ui <- shinyUI(
  shiny::fluidPage(
    h4('Shiny hierarchical checkbox')
    ,shinyTree("tree", checkbox = TRUE)
  )
)
shinyApp(ui, server)

enter image description here

How can I make this so that by default, none of the above are selected but are still displayed?

If I set both stselected = FALSE in the above code, I get

enter image description here

which is NOT what I want; I would just like the above with the checkboxes deselected.

Links to online references on further documentation with code would be extremely helpful. The package documentation for shinyTree is not helpful.


Solution

  • You can do it in such way :

    output$tree <- renderTree({ 
        sss=list(  'I lorem impsum'= list( 
          'I.1 lorem impsum'   =  structure(list('I.1.1 lorem impsum'='1', 'I.1.2 lorem impsum'='2'),stopened=TRUE),  
          'I.2 lorem impsum'   =  structure(list('I.2.1 lorem impsum'='3'), stopened=TRUE)))
        attr(sss[[1]],"stopened")=TRUE 
        sss
      })
    

    P.S

    Documentation is realy bad... I find stopened in shinyTree:::getJSON which used in shinyTree:::listToTags