-
Notifications
You must be signed in to change notification settings - Fork 3
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
Selected input loses hierarchy #7
Comments
I have found that I can achieve the desired functionality by embedding the hierarchy in the "data" field of each node (see below). However, using this method is undesirable because it blows out the size of the data that needs to be transferred to/from the client, and the information held in the data field is entirely redundant.
|
That's done. If you want to try it: library(jsTreeR)
library(shiny)
library(jsonlite)
nodes <- list(
list(
text = "RootA",
data = list(value = 999),
icon = "far fa-moon red",
children = list(
list(
text = "ChildA1",
icon = "fa fa-leaf green"
),
list(
text = "ChildA2",
data = list(value = 11111),
icon = "fa fa-leaf green"
)
)
),
list(
text = "RootB",
icon = "far fa-moon red",
children = list(
list(
text = "ChildB1",
icon = "fa fa-leaf green"
),
list(
text = "ChildB2",
icon = "fa fa-leaf green"
)
)
)
)
ui <- fluidPage(
tags$head(
tags$style(
HTML(c(
".red {color: red;}",
".green {color: green;}",
".jstree-proton {font-weight: bold;}",
".jstree-anchor {font-size: medium;}",
"pre {font-weight: bold; line-height: 1;}"
))
)
),
titlePanel("Drag and drop the nodes"),
fluidRow(
column(
width = 3,
jstreeOutput("jstree")
),
column(
width = 4,
tags$fieldset(
tags$legend(tags$span(style = "color: blue;", "All nodes")),
verbatimTextOutput("treeState")
)
),
column(
width = 4,
tags$fieldset(
tags$legend(tags$span(style = "color: blue;", "Selected nodes")),
verbatimTextOutput("treeSelected")
)
)
)
)
server <- function(input, output){
output[["jstree"]] <- renderJstree({
jstree(
nodes, dragAndDrop = TRUE, checkboxes = TRUE,
selectLeavesOnly = FALSE, theme = "proton"
)
})
output[["treeState"]] <- renderPrint({
toJSON(input[["jstree"]], pretty = TRUE, auto_unbox = TRUE)
})
output[["treeSelected"]] <- renderPrint({
toJSON(input[["jstree_selected_paths"]], pretty = TRUE, auto_unbox = TRUE)
})
}
shinyApp(ui, server)
|
Thanks! The forward-slash separator will be problematic - can Just to describe what I'm trying to do a bit more: the selected nodes will be turned into an SQL query to extract the relevant data and display it in the Shiny app. For example, using my menu structure: if I select the "Version 3" node the
In this case where all the leaf nodes are selected then I don't want to include them all in the SQL - that would be redundant and I can use the second-level value to pick up all the leaf node values; my SQL would end up something along the lines of So for this example I need to remove the last three nodes; I would do something like I hope that all makes sense. The reason I mention this is because I think this is probably a fairly common use-case, and it would be nice if the package included support for this. |
Hi, I don't know whether this will be appropriate for you but I implemented a new Shiny input value, To be available, you have to set Installation: |
I close, but feel free to reopen or to continue the discussion. I hope your problem is solved. |
I've got a fairly large menu structure (almost 10k menu items) and there is a lot of repetition in the leaf nodes - the parent level provides critical context which is needed to identify what data the leaf node relates to. From what I can see, just using
str()
to display the selected values, the results are returned as a one-dimensional list and the hierarchy is lost. Is there a way around this?I have started using jsTreeR after struggling with the limitations of
shinyTree
, but shinyTree did maintain the structure of the menu data, so I'm thinking this must be possible.Here is an example:
The text was updated successfully, but these errors were encountered: