'htmlwidget' for Interactive Views of R Lists

R lists, especially nested lists, can be very difficult to visualize or represent. Sometimes 'str()' is not enough, so this suite of htmlwidgets is designed to help see, understand, and maybe even modify your R lists. The function 'reactjson()' requires a package 'reactR' that can be installed from CRAN or < https://github.com/timelyportfolio/reactR>.


CRAN_Status_Badge Travis-CI Build Status A package of R htmlwidgets to interactively view and maybe modify lists. As of now, listviewer provides an interface to jsoneditor and react-json-view. listviewer is designed 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

reactjson

react-json-view is another very nice JSON interactive editor. We even get copy/paste! All of the above examples should also work with reactjson.

# using the data from the jsoneditor simple example
#  in R list form
 
library(listviewer)
 
reactjson(
  list(
    array = c(1,2,3)
    ,boolean = TRUE
    ,null = NULL
    ,number = 123
    ,object = list( a="b", c="d" )
    ,string = "Hello World"
  )
)

Shiny example

listviewer works with Shiny but the implementation is crude and likely to change for jsonedit while reactjson integration is much better. If you really want to use jsonedit with Shiny, I would recommend debouncing the change callback. Here are examples with each.

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 ) )
 
library(shiny)
library(listviewer)
 
# put some data in environment so it will show up
data(mtcars)
 
ui <- shinyUI(
  fluidPage(
    reactjsonOutput( "rjed" )
  )
)
 
server <- function(input,output){
  output$rjed <- renderReactjson({
    reactjson( as.list( .GlobalEnv ) )
  })
  
  observeEvent(input$rjed_edit, {
    str(input$rjed_edit, max.level=2)
  })
}
 
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.

News

listviewer 2.1.0

  • update jsoneditor to 5.24.6
  • update react-json-view to 2.5.7
  • add full set of props for react-json-view

listviewer 2.0.0

listviewer 1.4.0

  • add elementId to the jsonedit function
  • update react-json to 0.2.1
  • add helper number_unnamed function (see issue)

listviewer 1.3

listviewer 1.2

  • add RStudio addin capabilities

listviewer 1.1

  • add shiny gadget functionality with jsonedit_gadget

listviewer 1.0

  • Submit to CRAN.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("listviewer")

2.1.0 by Kent Russell, 8 months ago


https://github.com/timelyportfolio/listviewer


Report a bug at https://github.com/timelyportfolio/listviewer/issues


Browse source code at https://github.com/cran/listviewer


Authors: Jos de Jong [aut, cph] (jsoneditor.js library in htmlwidgets/jsoneditor , http://github.com/josdejong/jsoneditor/) , Mac Gainer [aut, cph] (react-json-view library in htmlwidgets/react-json , https://github.com/mac-s-g/react-json-view) , Kent Russell [aut, cre] (R interface)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports htmltools, htmlwidgets, shiny

Suggests jsonlite, miniUI, rstudioapi

Enhances reactR


Imported by sparklyr.nested.

Suggested by basictabler, d3r, pivottabler, plotly, vegawidget.


See at CRAN