Skip to content

Commit

Permalink
treeInput: select with ID
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Mar 1, 2023
1 parent bf0a001 commit 26838f9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion R/tree-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ treeInput <- function(inputId,
tags$script(
type = "application/json",
`data-for` = inputId,
config
HTML(config)
)
),
html_dependency_tree()
Expand Down
6 changes: 3 additions & 3 deletions examples/tree-default.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ui <- fluidPage(
inputId = "ID1",
label = "Select cities:",
choices = create_tree(cities),
# selected = "San Francisco",
selected = "San Francisco",
returnValue = "text",
closeDepth = 0
),
Expand All @@ -36,7 +36,7 @@ ui <- fluidPage(
inputId = "ID2",
label = "Select cities:",
choices = create_tree(cities),
# selected = "San Francisco",
selected = "San Francisco",
returnValue = "text",
closeDepth = 1
),
Expand All @@ -48,7 +48,7 @@ ui <- fluidPage(
inputId = "ID3",
label = "Select cities:",
choices = create_tree(cities),
# selected = "San Francisco",
selected = c("San Francisco", "Monastir"),
returnValue = "text",
closeDepth = 2
),
Expand Down
14 changes: 9 additions & 5 deletions examples/tree-update.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,21 @@ server <- function(input, output, session) {
updateTreeInput(inputId = "ID1", label = input$label)
)

observe(
observeEvent(
input$val_country,
updateTreeInput(inputId = "ID1", selected = input$val_country)
)

observe(
observeEvent(
input$val_city,
updateTreeInput(inputId = "ID1", selected = input$val_city)
)

observeEvent(
input$clear,
updateTreeInput(inputId = "ID1", selected = character(0))
observeEvent(input$clear, {
updateTreeInput(inputId = "ID1", selected = character(0))
updateCheckboxGroupInput(inputId = "val_country", selected = character(0))
updateCheckboxGroupInput(inputId = "val_city", selected = character(0))
}
)
}

Expand Down
2 changes: 1 addition & 1 deletion inst/packer/tree.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions man/treeInput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions man/updateTreeInput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion srcjs/inputs/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ $.extend(treeWidgetBinding, {
var tree = treeWidgetBinding.store[el.id];
var nodesId = tree.nodesById;
var checked = Object.entries(nodesId).map((a) => {
if (value.includes(a[1].text[0])) {
if (value.toString() === a[1].id[0].toString()) {
return a[1].id[0];
} else if (value.includes(a[1].text[0])) {
return a[1].id[0];
} else {
return null;
Expand Down

0 comments on commit 26838f9

Please sign in to comment.