reactjson: Edit R Data with 'react-json'

Description Usage Arguments Examples

View source: R/reactjson.R

Description

Edit R Data with 'react-json'

Usage

1
2
3
4
5
6
7
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 = FALSE,
  onAdd = FALSE, onDelete = FALSE, onSelect = FALSE, 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

htmlwidgets::JS function for callback to perform on edit.

onAdd

htmlwidgets::JS function for callback to perform on add.

onDelete

htmlwidgets::JS function for callback to perform on delete.

onSelect

htmlwidgets::JS function for callback to perform on select.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
## 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)

listviewer documentation built on Oct. 7, 2018, 9:04 a.m.