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

Update selection in server.R (shiny) #8

Open
castledan opened this issue Sep 7, 2022 · 3 comments
Open

Update selection in server.R (shiny) #8

castledan opened this issue Sep 7, 2022 · 3 comments

Comments

@castledan
Copy link

Hi,

Is there a way to change the value of the tree input on the client? Something like what updateCheckboxGroupInput does for checkboxGroupInput. What I would like to include in my app is a "Reset selection" button, which reverts the selection of the nodes in the tree to the default one.

@pvictor
Copy link
Member

pvictor commented Sep 8, 2022

If you re-install from GitHub you will have a updateTreeview function to update selected value.

To clear the selection use character(0), note that this doesn't work if you have set prevent_unselect option to TRUE.

Here's an example :

# updateTreeview ----------------------------------------------------------


library(shiny)
library(shinytreeview)

data("cities")

ui <- fluidPage(
  tags$h3("Update label & selected value"),
  treeviewInput(
    inputId = "tree",
    label = "Choose a city:",
    choices = make_tree(cities, c("continent", "country", "city")),
    multiple = FALSE,
    prevent_unselect = TRUE
  ),
  verbatimTextOutput(outputId = "result"),
  textInput("label", "New label:", "Choose a city:"),
  radioButtons(
    "selected", "Selected:",
    choices = unique(c(cities$continent, cities$country, cities$city)),
    inline = TRUE
  )
)

server <- function(input, output, session) {
  output$result <- renderPrint({
    input$tree
  })
  observe(updateTreeview(inputId = "tree", label = input$label))
  observe(updateTreeview(inputId = "tree", selected = input$selected))
}

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

@castledan
Copy link
Author

Thank you very much, it works well! I'll take advantage one last time of your availability and responsiveness and post another issue on a different topic.

@dmcalli2
Copy link

Thanks for sharing package. Looks great. Is it likely that you will add a "choices" argument to UpdateTreeview (as in the UpdateSelectInput)?

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