treeviewInput: Tree view Input

Description Usage Arguments Value Examples

View source: R/input-treeview.R

Description

Represent hierarchical tree structures to select a value in a nested list.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
treeviewInput(
  inputId,
  label = NULL,
  choices,
  selected = NULL,
  multiple = FALSE,
  levels = 1,
  borders = TRUE,
  prevent_unselect = FALSE,
  ...,
  return_value = c("name", "id", "all"),
  width = NULL
)

Arguments

inputId

The input slot that will be used to access the value.

label

Display label for the control, or NULL for no label.

choices

A list to be used as choices, can be created with make_tree.

selected

Default selected value, must correspond to the Id of the node.

multiple

Allow selection of multiple values.

levels

Sets the number of hierarchical levels deep the tree will be expanded to by default.

borders

Show or not borders around items.

prevent_unselect

When multiple = TRUE, prevent user to unselect a value.

...

Others parameters passed to JavaScript treeview method.

return_value

Value returned server-side, default is the element name, other possibilities are "id" (works only if nodes have an id) or "all" to returned all the tree under the element selected.

width

The width of the input, e.g. '400px', or '100%'.

Value

Server-side: A character value or a list depending on the return_value argument.

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
# Basic treeviewInput example --------------------------

library(shiny)
library(shinytreeview)

choices <- list(
  list(
    text = "Parent 1",
    nodes = list(
      list(text = "Child 1.1"),
      list(text = "Child 1.2")
    )
  ),
  list(text = "Parent 2"),
  list(text = "Parent 3"),
  list(
    text = "Parent 4",
    nodes = list(
      list(text = "Child 4.1"),
      list(text = "Child 4.2")
    )
  ),
  list(text = "Parent 5")
)


ui <- fluidPage(
  tags$h3("treeviewInput basic example"),
  treeviewInput(
    inputId = "tree", label = "Make a choice:",
    choices = choices, selected = "Parent 3",
    multiple = FALSE, prevent_unselect = TRUE
  ),
  verbatimTextOutput(outputId = "result")
)

server <- function(input, output, session) {
  output$result <- renderPrint({
    input$tree
  })
}

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

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