This function is useful for obtaining/viewing/debugging JSON sent to plotly.js.

plotly_json(p = last_plot(), jsonedit = interactive(), pretty = TRUE, ...)

Arguments

p

a plotly or ggplot object.

jsonedit

use listviewer::jsonedit to view the JSON?

pretty

adds indentation whitespace to JSON output. Can be TRUE/FALSE or a number specifying the number of spaces to indent. See jsonlite::prettify.

...

other options passed onto listviewer::jsonedit

Examples

  
plotly_json(plot_ly())
#> Warning: No trace type specified and no positional attributes specified
#> No trace type specified:
#>   Based on info supplied, a 'scatter' trace seems appropriate.
#>   Read more about this trace type -> https://plotly.com/r/reference/#scatter
#> No scatter mode specifed:
#>   Setting the mode to markers
#>   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
#> {
#>   "visdat": {
#>     "25368179a6de09": ["function () ", "plotlyVisDat"]
#>   },
#>   "cur_data": "25368179a6de09",
#>   "attrs": {
#>     "25368179a6de09": {
#>       "alpha_stroke": 1,
#>       "sizes": [10, 100],
#>       "spans": [1, 20]
#>     }
#>   },
#>   "layout": {
#>     "margin": {
#>       "b": 40,
#>       "l": 60,
#>       "t": 25,
#>       "r": 10
#>     },
#>     "xaxis": {
#>       "domain": [0, 1],
#>       "automargin": true
#>     },
#>     "yaxis": {
#>       "domain": [0, 1],
#>       "automargin": true
#>     },
#>     "hovermode": "closest",
#>     "showlegend": false
#>   },
#>   "source": "A",
#>   "config": {
#>     "modeBarButtonsToAdd": ["hoverclosest", "hovercompare"],
#>     "showSendToCloud": false
#>   },
#>   "data": [
#>     {
#>       "type": "scatter",
#>       "mode": "markers",
#>       "marker": {
#>         "color": "rgba(31,119,180,1)",
#>         "line": {
#>           "color": "rgba(31,119,180,1)"
#>         }
#>       },
#>       "error_y": {
#>         "color": "rgba(31,119,180,1)"
#>       },
#>       "error_x": {
#>         "color": "rgba(31,119,180,1)"
#>       },
#>       "line": {
#>         "color": "rgba(31,119,180,1)"
#>       },
#>       "xaxis": "x",
#>       "yaxis": "y",
#>       "frame": null
#>     }
#>   ],
#>   "highlight": {
#>     "on": "plotly_click",
#>     "persistent": false,
#>     "dynamic": false,
#>     "selectize": false,
#>     "opacityDim": 0.20000000000000001,
#>     "selected": {
#>       "opacity": 1
#>     },
#>     "debounce": 0
#>   },
#>   "shinyEvents": ["plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick"],
#>   "base_url": "https://plot.ly"
#> } 
plotly_json(plot_ly(), FALSE)
#> Warning: No trace type specified and no positional attributes specified
#> No trace type specified:
#>   Based on info supplied, a 'scatter' trace seems appropriate.
#>   Read more about this trace type -> https://plotly.com/r/reference/#scatter
#> No scatter mode specifed:
#>   Setting the mode to markers
#>   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
#> {
#>   "visdat": {
#>     "25368152b2ceed": ["function () ", "plotlyVisDat"]
#>   },
#>   "cur_data": "25368152b2ceed",
#>   "attrs": {
#>     "25368152b2ceed": {
#>       "alpha_stroke": 1,
#>       "sizes": [10, 100],
#>       "spans": [1, 20]
#>     }
#>   },
#>   "layout": {
#>     "margin": {
#>       "b": 40,
#>       "l": 60,
#>       "t": 25,
#>       "r": 10
#>     },
#>     "xaxis": {
#>       "domain": [0, 1],
#>       "automargin": true
#>     },
#>     "yaxis": {
#>       "domain": [0, 1],
#>       "automargin": true
#>     },
#>     "hovermode": "closest",
#>     "showlegend": false
#>   },
#>   "source": "A",
#>   "config": {
#>     "modeBarButtonsToAdd": ["hoverclosest", "hovercompare"],
#>     "showSendToCloud": false
#>   },
#>   "data": [
#>     {
#>       "type": "scatter",
#>       "mode": "markers",
#>       "marker": {
#>         "color": "rgba(31,119,180,1)",
#>         "line": {
#>           "color": "rgba(31,119,180,1)"
#>         }
#>       },
#>       "error_y": {
#>         "color": "rgba(31,119,180,1)"
#>       },
#>       "error_x": {
#>         "color": "rgba(31,119,180,1)"
#>       },
#>       "line": {
#>         "color": "rgba(31,119,180,1)"
#>       },
#>       "xaxis": "x",
#>       "yaxis": "y",
#>       "frame": null
#>     }
#>   ],
#>   "highlight": {
#>     "on": "plotly_click",
#>     "persistent": false,
#>     "dynamic": false,
#>     "selectize": false,
#>     "opacityDim": 0.20000000000000001,
#>     "selected": {
#>       "opacity": 1
#>     },
#>     "debounce": 0
#>   },
#>   "shinyEvents": ["plotly_hover", "plotly_click", "plotly_selected", "plotly_relayout", "plotly_brushed", "plotly_brushing", "plotly_clickannotation", "plotly_doubleclick", "plotly_deselect", "plotly_afterplot", "plotly_sunburstclick"],
#>   "base_url": "https://plot.ly"
#> }