make_tree: Create choice structure for 'treeviewInput'

Description Usage Arguments Value Examples

View source: R/input-treeview.R

Description

Create choice structure for treeviewInput

Usage

1
make_tree(data, levels, selected = NULL, ...)

Arguments

data

A data.frame.

levels

Variables identifying hierarchical levels.

selected

Default selected value(s).

...

Named arguments with list of attributes to apply to a certain level. Names must be the same as the levels. Full list of attributes is available at the following URL : https://github.com/patternfly/patternfly-bootstrap-treeview#node-properties.

Value

a list that can be used in treeviewInput.

Examples

 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
56
57
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)

zehndert/shinytreeviewCustom documentation built on Dec. 23, 2021, 9:15 p.m.