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
)

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

if (FALSE) {

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

}