Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for expand/collapse is broken #12

Open
razz-matazz opened this issue Apr 6, 2023 · 2 comments
Open

Example for expand/collapse is broken #12

razz-matazz opened this issue Apr 6, 2023 · 2 comments

Comments

@razz-matazz
Copy link

razz-matazz commented Apr 6, 2023

Hello,

In the docs there is an example for expand/collapse.
I justed wanted to let you know that the actionButton "expandWAfrica" cannot work, because nodes_input = TRUE isn't set in treeviewInput.

Further I do not know if it is the intented behaviour that then the countrys of level 3 are then displayed directly under level 1. I would assume level 2 (e.g. western africa) is still displayed (but now expanded).

@pvictor
Copy link
Member

pvictor commented Apr 7, 2023

Thanks for reporting, I've updated the example.
Indeed, I'm agree, I've updated the behavior to expand parent node as well.

Victor

@WurmPeter
Copy link

WurmPeter commented Apr 12, 2023

Hm, I think this caused a new bug.
When levels = 1, setting selected in treeviewInput shows now the selected third-level item directly under its first-level item, skipping the second-level...

Here's an example:

library(shinytreeview)

dat_fr <- data.frame(
  first_level_id = c("f1", "f2", "f1", "f3", "f2"),
  second_level_id = c("b1", "b2", "b3", "b3", "b4"),
  third_level_id = c("1", "2", "3", "4", "5"),
  first_level = c(
    "A",
    "B",
    "A",
    "C",
    "B"
  ),
  second_level = c(
    "A-1",
    "B-1",
    "A-2",
    "C-1",
    "B-2"
  ),
  third_level = c(
    "item 1",
    "item 2",
    "item 3",
    "item 4",
    "item 5"
  ),
  stringsAsFactors = FALSE
)

ui <- fluidPage( 
  fluidRow(
    column(
      width = 4, 
      uiOutput("tree")
    ),
    column(
      width = 8, 
      tags$b("Selected:"),
      verbatimTextOutput(outputId = "result")
    )
  )
)

server <- function(input, output, session) {
  
  output$result <- renderPrint({
    input$selected_item
  })
  
  output$tree <- renderUI({
    tagList(
      shinytreeview::treeviewInput(
        inputId = "selected_item",
        levels = 1,
        borders = FALSE,
        selected = "2",
        return_value = "id",
        choices = shinytreeview::make_tree( 
          dat_fr, 
          levels = c("first_level", "second_level", "third_level"),
          levels_id = c("first_level_id", "second_level_id", "third_level_id") 
        ),
        width = "100%"
      )
    )
  })
  
}

if (interactive())
  shinyApp(ui, server)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants