Learn R Programming

⚠️There's a newer version (4.0.0) of this package.Take me there.

listviewer

A package of R htmlwidgets to interactively view and maybe modify lists. As of now, listviewer provides just one interface to jsoneditor. listviewer is designed though to support multiple interfaces.

install

CRAN

install.packages("listviewer")

Development Version

devtools::install_github("timelyportfolio/listviewer")

jsoneditor

jsoneditor is a really well designed JSON interactive editor by Jos de Jong. Since most R data can be represented in JSON, we can use this great JavaScript library in R.

# using the data from the jsoneditor simple example
#  in R list form

library(listviewer)

jsonedit(
  list(
    array = c(1,2,3)
    ,boolean = TRUE
    ,null = NULL
    ,number = 123
    ,object = list( a="b", c="d" )
    ,string = "Hello World"
  )
)
# also works with data.frames
jsonedit( mtcars )
# helpful interactive view of par
jsonedit( par() )
# meta view of the above
jsonedit(jsonedit(par()))

See the above interactive view of par for yourself.

I got this idea courtesy of @jasonpbecker on Twitter. htmlwidgets dependencies are defined by YAML. Let's see the dependencies for jsonedit.

jsonedit(
  yaml.load_file(system.file("htmlwidgets/jsonedit.yaml",package="listviewer"))
)

How about topojson?

### experiment with topojson
library(httr)
library(pipeR)
library(listviewer)

# topojson for Afghanistan
url_path = "https://gist.githubusercontent.com/markmarkoh/8856417/raw/6178d18115d9f273656d294a867c3f83b739a951/customAfghanMap.topo.json"

url_path %>>% 
  GET %>>%
  content( as = "text") %>>%
  jsonedit

Shiny example

listviewer works with Shiny but the implementation is crude and likely to change. Here is an example. If you really want to use it, I would recommend debouncing the change callback.

library(shiny)
library(listviewer)

# put some data in environment so it will show up
data(mtcars)

ui <- shinyUI(
  fluidPage(
    jsoneditOutput( "jsed" )
  )
)

server <- function(input,output){
  output$jsed <- renderJsonedit({
    jsonedit(
      as.list( .GlobalEnv )
      ,"change" = htmlwidgets::JS('function(){
        console.log( event.currentTarget.parentNode.editor.get() )
      }')
    )
    
  })
}

runApp( list( ui = ui, server = server ) )

code of conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Copy Link

Version

Install

install.packages('listviewer')

Monthly Downloads

28,329

Version

1.4.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Kent Russell

Last Published

November 3rd, 2016

Functions in listviewer (1.4.0)

jsonedit

View Lists with 'jsoneditor'
listviewer

listviewer.
jsonedit-shiny

Shiny Bindings for `jsonedit`
number_unnamed

Number Starting at 1
reactjson

Edit R Data with 'react-json'
jsoneditAddin

jsoneditAddin
recurse

Recurse Over Nested Lists
reactjson-shiny

Shiny bindings for reactjson
jsonedit_gadget

Shiny Gadget for 'jsonedit'