View source: R/input-treeview.R
make_tree | R Documentation |
treeviewInput()
Create choice structure for treeviewInput()
make_tree(data, levels, selected = NULL, levels_id = NULL, ...)
data |
A |
levels |
Variables identifying hierarchical levels, values of those variables will be used as text displayed. |
selected |
Default selected value(s). |
levels_id |
Variable to use as ID, thos values wont't
be displayed but can be retrieved server-side with |
... |
Named arguments with |
a list
that can be used in treeviewInput()
or treecheckInput()
.
library(shinytreeview)
data("cities")
head(cities)
# Create choices that can be used in treeviewInput
make_tree(cities, c("continent", "country", "city"))
# Custom attributes for continent level
make_tree(cities, c("continent", "country", "city"), continent = list(selectable = FALSE))
library(shiny)
ui <- fluidPage(
tags$h3("treeviewInput cities example"),
fluidRow(
column(
width = 6,
treeviewInput(
inputId = "tree1",
label = "Choose an area:",
choices = make_tree(cities, c("continent", "country", "city")),
multiple = FALSE,
prevent_unselect = TRUE
),
verbatimTextOutput(outputId = "result1")
),
column(
width = 6,
treeviewInput(
inputId = "tree2",
label = "Choose an area (continent not selectable):",
choices = make_tree(
cities, c("continent", "country", "city"),
continent = list(selectable = FALSE)
),
multiple = FALSE,
prevent_unselect = TRUE
),
verbatimTextOutput(outputId = "result2")
)
)
)
server <- function(input, output, session) {
output$result1 <- renderPrint({
input$tree1
})
output$result2 <- renderPrint({
input$tree2
})
}
if (interactive())
shinyApp(ui, server)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.