% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/input-treeview.R
\name{make_tree}
\alias{make_tree}
\title{Create choice structure for \code{\link[=treeviewInput]{treeviewInput()}}}
\usage{
make_tree(data, levels, selected = NULL, levels_id = NULL, ...)
}
\arguments{
\item{data}{A \code{data.frame}.}

\item{levels}{Variables identifying hierarchical levels,
values of those variables will be used as text displayed.}

\item{selected}{Default selected value(s).}

\item{levels_id}{Variable to use as ID, thos values wont't
be displayed but can be retrieved server-side with \code{return_value = "id"}.}

\item{...}{Named arguments with \code{list} of attributes
to apply to a certain level. Names must be the same as the \code{levels}.
See
\href{https://github.com/patternfly/patternfly-bootstrap-treeview#node-properties}{full list of attributes}.}
}
\value{
a \code{list} that can be used in \code{\link[=treeviewInput]{treeviewInput()}} or \code{\link[=treecheckInput]{treecheckInput()}}.
}
\description{
Create choice structure for \code{\link[=treeviewInput]{treeviewInput()}}
}
\examples{
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)
}
