Description Usage Arguments Value Examples
Expand or collapse a treeviewInput
1 2 3 4 5 6 7 8 9 10 11 12 | expandTreeview(
inputId,
nodeId = NULL,
levels = 1,
session = shiny::getDefaultReactiveDomain()
)
collapseTreeview(
inputId,
nodeId = NULL,
session = shiny::getDefaultReactiveDomain()
)
|
inputId |
The id of the input object. |
nodeId |
Id of the node to expand or collapse,
use |
levels |
Levels to expand. |
session |
The session object passed to function given to shinyServer. |
None.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | library(shiny)
library(shinytreeview)
data("countries")
ui <- fluidPage(
tags$h3("treeviewInput expand/collapse example"),
fluidRow(
column(
width = 4,
treeviewInput(
inputId = "country",
label = "Choose a country:",
choices = make_tree(
countries, c("continent", "subregion", "name")
),
width = "100%"
)
),
column(
width = 8,
actionButton("expandAll", "Expand all"),
actionButton("expandWAfrica", "Expand Western Africa"),
actionButton("collapseAll", "Collapse all"),
tags$br(),
tags$b("Selected country:"),
verbatimTextOutput(outputId = "result")
)
)
)
server <- function(input, output, session) {
output$result <- renderPrint({
input$country
})
observeEvent(input$expandAll, {
expandTreeview("country", levels = 3)
})
observeEvent(input$expandWAfrica, {
nodes <- input$country_nodes
w_africa <- nodes[nodes$text == "Western Africa", "nodeId"]
print(w_africa)
expandTreeview("country", nodeId = w_africa, levels = 3)
})
observeEvent(input$collapseAll, {
collapseTreeview("country")
})
}
if (interactive())
shinyApp(ui, server)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.