3 min read

Week15 - List Viewer

Week15 - List Viewer

htmlwidgets News This Week

htmlwidgets now uses jsonlite. I recommend anyone serious about their widgets to read through the discussion of pull #28. Whether you care about the details or not, I would encourage updatating jsonlite, htmlwidgets, and Shiny with

devtools::install_github(c(
  'jeroenooms/jsonlite'
  , 'rstudio/shiny'
  , 'ramnathv/htmlwidgets'
))

For all the newest and updated htmlwidgets, just do this Github search, and you’ll quickly get up to date.

This Week’s Widget - listviewer

Last week’s exportwidget got almost no love, so I’m hoping this one finds a loving home. I have not been able to stop using it, since the first hour of creation, so it has quickly become a key component in my workflow.

With a tweet, Jennifer Bryan inspired this widget. Nested data gets messy, inscrutable, and difficult to follow very quickly. lists and environments in R are the primary source of this nested data. Often, an interactive visual look provides the insight and understanding one needs. listviewer gives us this view with just one line of code. We can use it to inspect htmlwidgets or lattice plots or par() settings or your .GlobalEnv.

Thanks so much to the Jos de Jong, the author of jsoneditor on which listviewer relies for all its awesomeness. If you look at the source of listviewer, you will notice how little code I had to write to wrap this as an htmlwidget.

Quick Installation

As with almost all widgets posted here, listviewer is not on CRAN, so for now please install with devtools::install_github. Given enough interest, I’m happy to put in the effort to make this or any others CRAN-worthy. Just let me know.

devtools::install_github("timelyportfolio/listviewer")

Examples

What’s my par?

When I first learned R I struggled with all the stuff in par(). Let’s see if this makes a little more sense.

library(listviewer)

jsonedit( par() )

What’s in my lattice?

lattice plots become trellis objects. Let’s peek inside. If you’re thinking let’s do the same with ggplot2, you’ll need to write a little more code to handle S3, S4, and environments.

library(lattice)
library(listviewer)

jsonedit(
  xyplot( y~x, data.frame( x = 1:10, y = 1:10 ), type = "b" )
)

What’s in my broom?

David Robinson’s broom package tidies up our messy data in R. Let’s see the difference with jsonedit.

jsonedit(
  list(
    "messy" = lm(mpg~factor(cyl),mtcars)
    ,"broom" = list(
      "tidy" = broom::tidy(lm(mpg~factor(cyl),mtcars))
      ,"augment" = broom::augment(lm(mpg~factor(cyl),mtcars))
    )
  )
)

What’s in my htmlwidget?

I hope you can see some of the power of this htmlwidget. As a final example, let’s go meta and jsonedit our jsonedit.

library(listviewer)

jsonedit(jsonedit())

Shiny?

listviewer sort of works with Shiny. modify and save for listviewer is the next frontier. See the Readme.md.

Thanks

Thanks so much

  • jsoneditor from Jos de Jong
  • Ramnath Vaidyanathan and RStudio for htmlwidgets
  • all the contributors to R and JavaScript