Title: | 'htmlwidget' for Interactive Views of R Lists |
---|---|
Description: | 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>. |
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) |
Maintainer: | Kent Russell <[email protected]> |
License: | MIT + file LICENSE |
Version: | 4.0.0 |
Built: | 2024-10-24 02:42:20 UTC |
Source: | https://github.com/timelyportfolio/listviewer |
Lists
with 'jsoneditor'
jsonedit
provides a flexible and helpful interactive tree-like view of lists
or really any R dataset that can be represented as JSON
.
Eventually, this could become a very nice way to not only view but also modify R data using
Shiny.
jsonedit( listdata = NULL, mode = "tree", modes = c("text", "tree", "table"), ..., width = NULL, height = NULL, elementId = NULL )
jsonedit( listdata = NULL, mode = "tree", modes = c("text", "tree", "table"), ..., width = NULL, height = NULL, elementId = NULL )
listdata |
|
mode |
|
modes |
|
... |
|
width |
integer in pixels defining the width of the |
height |
integer in pixels defining the height of the |
elementId |
character to specify valid |
library(listviewer) # using the data from the jsoneditor simple example # in R list form jsonedit( list( array = c(1,2,3) ,boolean = TRUE ,null = NULL ,number = 123 ,object = list( a="b", c="d" ) ,string = "Hello World" ) ) # jsonedit also works with a JSON string jsonedit( '{"array" : [1,2,3] , "boolean" : true, "null" : null, "number": 123}' ) # also works with most data.frames jsonedit( mtcars ) # helpful interactive view of par jsonedit( par() )
library(listviewer) # using the data from the jsoneditor simple example # in R list form jsonedit( list( array = c(1,2,3) ,boolean = TRUE ,null = NULL ,number = 123 ,object = list( a="b", c="d" ) ,string = "Hello World" ) ) # jsonedit also works with a JSON string jsonedit( '{"array" : [1,2,3] , "boolean" : true, "null" : null, "number": 123}' ) # also works with most data.frames jsonedit( mtcars ) # helpful interactive view of par jsonedit( par() )
Provides a Shiny gadget
interface for jsonedit
to interactively edit and return the
changes for use in R.
jsonedit_gadget(..., height = NULL, width = NULL)
jsonedit_gadget(..., height = NULL, width = NULL)
... |
arguments for |
height , width
|
any valid |
## Not run: library(listviewer) jsonedit_gadget( structure( as.list(1:4), names=letters[1:4] ) ) ## End(Not run)
## Not run: library(listviewer) jsonedit_gadget( structure( as.list(1:4), names=letters[1:4] ) ) ## End(Not run)
Output and render functions for using jsonedit within Shiny applications and interactive Rmd documents.
jsoneditOutput(outputId, width = "100%", height = "400px") renderJsonedit(expr, env = parent.frame(), quoted = FALSE)
jsoneditOutput(outputId, width = "100%", height = "400px") renderJsonedit(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a jsonedit |
env |
The environment in which to evaluate |
quoted |
Is |
htmlwidget for interactive views of R lists
R lists, especially nested lists, can be very difficult to visualize or
represent. str
just isn't enough, so this suite of htmlwidgets is
designed to help see, understand, and maybe even modify your R lists.
1
JavaScript starts at 0
, but R starts at 1
.
This means unnamed lists and vectors are indexed starting at
0
in listviewer widgets. This little helper function
tries to resolve the disconnect by assigning sequential numbers
starting at 1
to names for unnamed lists
and vectors
.
Please note though that using number_unnamed
will potentially
cause difficulties serializing back and forth between JavaScript and R.
number_unnamed(l)
number_unnamed(l)
l |
|
library(listviewer) jsonedit( number_unnamed(list(x=list(letters[1:3]))) )
library(listviewer) jsonedit( number_unnamed(list(x=list(letters[1:3]))) )
Edit R Data with 'react-json'
reactjson( listdata = list(), name = "root", theme = "rjv-default", iconStyle = c("circle", "triangle", "square"), indentWidth = 4, collapsed = FALSE, collapseStringsAfterLength = FALSE, groupArraysAfterLength = 100, enableClipboard = TRUE, displayObjectSize = TRUE, displayDataTypes = TRUE, onEdit = TRUE, onAdd = TRUE, onDelete = TRUE, onSelect = TRUE, sortKeys = FALSE, width = NULL, height = NULL, elementId = NULL )
reactjson( listdata = list(), name = "root", theme = "rjv-default", iconStyle = c("circle", "triangle", "square"), indentWidth = 4, collapsed = FALSE, collapseStringsAfterLength = FALSE, groupArraysAfterLength = 100, enableClipboard = TRUE, displayObjectSize = TRUE, displayDataTypes = TRUE, onEdit = TRUE, onAdd = TRUE, onDelete = TRUE, onSelect = TRUE, sortKeys = FALSE, width = NULL, height = NULL, elementId = NULL )
listdata |
|
name |
|
theme |
|
iconStyle |
|
indentWidth |
|
collapsed |
|
collapseStringsAfterLength |
|
groupArraysAfterLength |
|
enableClipboard |
|
displayObjectSize |
|
displayDataTypes |
|
onEdit , onAdd , onDelete , onSelect
|
|
sortKeys |
|
width |
integer in pixels defining the width of the |
height |
integer in pixels defining the height of the |
elementId |
character to specify valid |
## Not run: library(listviewer) # use reactR for React dependencies # devtools::install_github("timelyportfolio/reactR") library(reactR) reactjson() reactjson(head(mtcars,4)) reactjson(I(jsonlite::toJSON(head(mtcars,5)))) library(shiny) shinyApp( ui = reactjson( list(x=1,msg="react+r+shiny",opts=list(use_react=FALSE)), elementId = "json1" ), server = function(input, output, session){ observeEvent( input$json1_change, str(input$json1_change) ) } ) # gadget to use as editor library(miniUI) ui <- miniUI::miniPage( miniUI::miniContentPanel( reactjson( list(x=1,msg="react+r+shiny",opts=list(use_react=FALSE)), elementId = "rjeditor" ) ), miniUI::gadgetTitleBar( "Edit", right = miniUI::miniTitleBarButton("done", "Done", primary = TRUE) ) ) server <- function(input, output, session) { shiny::observeEvent(input$done, { shiny::stopApp( input$rjeditor_change ) }) shiny::observeEvent(input$cancel, { shiny::stopApp (NULL) }) } runGadget( ui, server, viewer = shiny::paneViewer() ) ## End(Not run)
## Not run: library(listviewer) # use reactR for React dependencies # devtools::install_github("timelyportfolio/reactR") library(reactR) reactjson() reactjson(head(mtcars,4)) reactjson(I(jsonlite::toJSON(head(mtcars,5)))) library(shiny) shinyApp( ui = reactjson( list(x=1,msg="react+r+shiny",opts=list(use_react=FALSE)), elementId = "json1" ), server = function(input, output, session){ observeEvent( input$json1_change, str(input$json1_change) ) } ) # gadget to use as editor library(miniUI) ui <- miniUI::miniPage( miniUI::miniContentPanel( reactjson( list(x=1,msg="react+r+shiny",opts=list(use_react=FALSE)), elementId = "rjeditor" ) ), miniUI::gadgetTitleBar( "Edit", right = miniUI::miniTitleBarButton("done", "Done", primary = TRUE) ) ) server <- function(input, output, session) { shiny::observeEvent(input$done, { shiny::stopApp( input$rjeditor_change ) }) shiny::observeEvent(input$cancel, { shiny::stopApp (NULL) }) } runGadget( ui, server, viewer = shiny::paneViewer() ) ## End(Not run)
Output and render functions for using reactjson within Shiny applications and interactive Rmd documents.
reactjsonOutput(outputId, width = "100%", height = "400px") renderReactjson(expr, env = parent.frame(), quoted = FALSE)
reactjsonOutput(outputId, width = "100%", height = "400px") renderReactjson(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a reactjson |
env |
The environment in which to evaluate |
quoted |
Is |