Package 'listviewer'

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

Help Index


View Lists with 'jsoneditor'

Description

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.

Usage

jsonedit(
  listdata = NULL,
  mode = "tree",
  modes = c("text", "tree", "table"),
  ...,
  width = NULL,
  height = NULL,
  elementId = NULL
)

Arguments

listdata

list or String data to view. Although designed for lists, listdata can be any data source that can be rendered into JSON with jsonlite. Alternately, listdata could be a String of valid JSON. This might be helpful when dealing with an API response.

mode

string for the initial view from modes. 'tree' is the default.

modes

string c('tree', 'text', 'table') will be the default, since these are all the modes currently supported by jsoneditor.

...

list of other options for jsoneditor. This is a temporary way of trying other options in jsoneditor. In the future, this will be eliminated in favor of specific, more self-documenting and helpful arguments.

width

integer in pixels defining the width of the div container.

height

integer in pixels defining the height of the div container.

elementId

character to specify valid CSS id of the htmlwidget for special situations in which you want a non-random identifier.

Examples

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() )

Shiny Gadget for 'jsonedit'

Description

Provides a Shiny gadget interface for jsonedit to interactively edit and return the changes for use in R.

Usage

jsonedit_gadget(..., height = NULL, width = NULL)

Arguments

...

arguments for jsonedit

height, width

any valid CSS size unit for the height and width of the gadget

Examples

## Not run: 
library(listviewer)

jsonedit_gadget(
  structure(
    as.list(1:4),
    names=letters[1:4]
  )
)

## End(Not run)

Shiny Bindings for 'jsonedit'

Description

Output and render functions for using jsonedit within Shiny applications and interactive Rmd documents.

Usage

jsoneditOutput(outputId, width = "100%", height = "400px")

renderJsonedit(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

expr

An expression that generates a jsonedit

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.


listviewer.

Description

htmlwidget for interactive views of R lists

Details

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.


Number Starting at 1

Description

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.

Usage

number_unnamed(l)

Arguments

l

list

Examples

library(listviewer)
jsonedit(
  number_unnamed(list(x=list(letters[1:3])))
)

Edit R Data with 'react-json'

Description

Edit R Data with 'react-json'

Usage

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
)

Arguments

listdata

list or String data to view. Although designed for lists, listdata can be any data source that can be rendered into JSON with jsonlite. Alternately, listdata could be a String of valid JSON. This might be helpful when dealing with an API response.

name

string name of the root node. Default is "root".

theme

string name of the theme. Default is "rjv-default".

iconStyle

string shape for the expand/collapse icon. Options are circle, triangle, and square with the default as "circle".

indentWidth

integer for the indent width for nested objects. Default is 4.

collapsed

logical or integer. Use logical to expand/collapse all nodes. Use integer to specify the depth at which to collapse.

collapseStringsAfterLength

integer for the length at which strings will be cut off Collapsed strings are followed by an ellipsis. String content can be expanded and collapsed by clicking on the string value.

groupArraysAfterLength

integer for the count at which arrays will be displayed in groups. Groups are displayed with bracket notation and can be expanded and collapsed. by clicking on the brackets.

enableClipboard

logical whether the user can copy objects and arrays clicking on the clipboard icon. Copy callbacks are supported. Default is TRUE.

displayObjectSize

logical whether or not objects and arrays are labeled with size. Default is TRUE.

displayDataTypes

logical whether or not data type labels prefix values. Default is TRUE.

onEdit, onAdd, onDelete, onSelect

htmlwidgets::JS or logical to control behavior on edit, add, delete, and select. If htmlwidgets::JS function is provided, then the function will be performed on each event. If logical then TRUE means that the event will be passed to Shiny and FALSE will disable the behavior. The default is TRUE.

sortKeys

logical whether or not to sort object keys. Default is FALSE.

width

integer in pixels defining the width of the div container.

height

integer in pixels defining the height of the div container.

elementId

character to specify valid CSS id of the htmlwidget for special situations in which you want a non-random identifier.

Examples

## 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)

Shiny bindings for reactjson

Description

Output and render functions for using reactjson within Shiny applications and interactive Rmd documents.

Usage

reactjsonOutput(outputId, width = "100%", height = "400px")

renderReactjson(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from

width, height

Must be a valid CSS unit (like '100%', '400px', 'auto') or a number, which will be coerced to a string and have 'px' appended.

expr

An expression that generates a reactjson

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.