df_to_list: Convert data.frame objects to list-of-lists format

Description Usage Arguments Value Examples

View source: R/df_to_list.R

Description

Convert a data.frame to a list of lists for compatibility with dashDataTable. The function will return a nested list object in which the sublists contain named elements of varying type; the names correspond to the column names in the original data.frame.

Usage

1

Arguments

df

A data.frame object, which will be transformed into a list of lists. Each row will become a single named list, in which the elements are named as the columns from which they were extracted.

Value

a list object, in which the sublists are named elements of varying type; the names correspond to the column names in the data.frame specified by df.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# first, create data frame
df <- read.csv(url(
  'https://raw.githubusercontent.com/plotly/datasets/master/solar.csv'
  ),
  check.names=FALSE,
  stringsAsFactors=FALSE
)

# then convert to list-of-lists format for use in dashTable
# the following snippet below will print as JSON
# see the help for dashDataTable to see an actual app example
dashDataTable(
  id = 'table',
  columns = lapply(colnames(df), function(x) {
    list(name = x, id = x)
  }),
  data = df_to_list(df)
)

dashTable documentation built on July 2, 2020, 2:35 a.m.