Skip to contents

listviewerlite provides a single function listview(), which creates a collapsible tree view of R lists using only HTML and CSS, without the need for JavaScript.

Installation

You can install the development version of listviewerlite from GitHub with:

# install.packages("devtools")
devtools::install_github("long39ng/listviewerlite")

Example

library(listviewerlite)

x <- list(
  list(id = "a", val = 2),
  list(
    id = "b",
    val = 1,
    children = list(
      list(id = "b1", val = 2.5),
      list(
        id = "b2",
        val = 8,
        children = list(
          list(id = "b21", val = 4)
        )
      )
    )
  ),
  list(
    id = "c",
    val = 8,
    children = list(
      list(id = "c1"),
      list(id = "c2", val = 1)
    )
  )
)

listview(x)

Acknowledgements

This package is inspired by {listviewer}, which wraps the JavaScript libraries jsoneditor and react-json-view.

The implementation of the listview() function is inspired by utils::str() and lobstr::tree().

The custom CSS properties for the collapsible tree view are copied and modified from the blog post by Kate Rose Morley.