Open razz-matazz opened 1 year ago
Thanks for reporting, I've updated the example. Indeed, I'm agree, I've updated the behavior to expand parent node as well.
Victor
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)
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 intreeviewInput
.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).