This generic function creates the list object sent to plotly.js for rendering. Using this function can be useful for overriding defaults provided by ggplotly/plot_ly or for debugging rendering errors.

plotly_build(p, registerFrames = TRUE)

Arguments

p

a ggplot object, or a plotly object, or a list.

registerFrames

should a frame trace attribute be interpreted as frames in an animation?

Examples


p <- plot_ly(economics, x = ~date, y = ~pce)
# the unevaluated plotly object
str(p)
#> List of 8
#>  $ x            :List of 6
#>   ..$ visdat  :List of 1
#>   .. ..$ 2536813a4f55a:function ()  
#>   ..$ cur_data: chr "2536813a4f55a"
#>   ..$ attrs   :List of 1
#>   .. ..$ 2536813a4f55a:List of 5
#>   .. .. ..$ x           :Class 'formula'  language ~date
#>   .. .. .. .. ..- attr(*, ".Environment")=<environment: 0x5649b25546e8> 
#>   .. .. ..$ y           :Class 'formula'  language ~pce
#>   .. .. .. .. ..- attr(*, ".Environment")=<environment: 0x5649b25546e8> 
#>   .. .. ..$ alpha_stroke: num 1
#>   .. .. ..$ sizes       : num [1:2] 10 100
#>   .. .. ..$ spans       : num [1:2] 1 20
#>   ..$ layout  :List of 3
#>   .. ..$ width : NULL
#>   .. ..$ height: NULL
#>   .. ..$ margin:List of 4
#>   .. .. ..$ b: num 40
#>   .. .. ..$ l: num 60
#>   .. .. ..$ t: num 25
#>   .. .. ..$ r: num 10
#>   ..$ source  : chr "A"
#>   ..$ config  :List of 2
#>   .. ..$ modeBarButtonsToAdd: chr [1:2] "hoverclosest" "hovercompare"
#>   .. ..$ showSendToCloud    : logi FALSE
#>   ..- attr(*, "TOJSON_FUNC")=function (x, ...)  
#>  $ width        : NULL
#>  $ height       : NULL
#>  $ sizingPolicy :List of 7
#>   ..$ defaultWidth : chr "100%"
#>   ..$ defaultHeight: num 400
#>   ..$ padding      : num 0
#>   ..$ fill         : NULL
#>   ..$ viewer       :List of 6
#>   .. ..$ defaultWidth : NULL
#>   .. ..$ defaultHeight: NULL
#>   .. ..$ padding      : NULL
#>   .. ..$ fill         : logi TRUE
#>   .. ..$ suppress     : logi FALSE
#>   .. ..$ paneHeight   : NULL
#>   ..$ browser      :List of 5
#>   .. ..$ defaultWidth : NULL
#>   .. ..$ defaultHeight: NULL
#>   .. ..$ padding      : NULL
#>   .. ..$ fill         : logi TRUE
#>   .. ..$ external     : logi FALSE
#>   ..$ knitr        :List of 3
#>   .. ..$ defaultWidth : NULL
#>   .. ..$ defaultHeight: NULL
#>   .. ..$ figure       : logi TRUE
#>  $ dependencies :List of 5
#>   ..$ :List of 10
#>   .. ..$ name      : chr "typedarray"
#>   .. ..$ version   : chr "0.1"
#>   .. ..$ src       :List of 1
#>   .. .. ..$ file: chr "htmlwidgets/lib/typedarray"
#>   .. ..$ meta      : NULL
#>   .. ..$ script    : chr "typedarray.min.js"
#>   .. ..$ stylesheet: NULL
#>   .. ..$ head      : NULL
#>   .. ..$ attachment: NULL
#>   .. ..$ package   : chr "plotly"
#>   .. ..$ all_files : logi FALSE
#>   .. ..- attr(*, "class")= chr "html_dependency"
#>   ..$ :List of 10
#>   .. ..$ name      : chr "jquery"
#>   .. ..$ version   : chr "3.5.1"
#>   .. ..$ src       :List of 1
#>   .. .. ..$ file: chr "lib/jquery"
#>   .. ..$ meta      : NULL
#>   .. ..$ script    : chr "jquery.min.js"
#>   .. ..$ stylesheet: NULL
#>   .. ..$ head      : NULL
#>   .. ..$ attachment: NULL
#>   .. ..$ package   : chr "crosstalk"
#>   .. ..$ all_files : logi TRUE
#>   .. ..- attr(*, "class")= chr "html_dependency"
#>   ..$ :List of 10
#>   .. ..$ name      : chr "crosstalk"
#>   .. ..$ version   : chr "1.2.1"
#>   .. ..$ src       :List of 1
#>   .. .. ..$ file: chr "www"
#>   .. ..$ meta      : NULL
#>   .. ..$ script    : chr "js/crosstalk.min.js"
#>   .. ..$ stylesheet: chr "css/crosstalk.min.css"
#>   .. ..$ head      : NULL
#>   .. ..$ attachment: NULL
#>   .. ..$ package   : chr "crosstalk"
#>   .. ..$ all_files : logi TRUE
#>   .. ..- attr(*, "class")= chr "html_dependency"
#>   ..$ :List of 10
#>   .. ..$ name      : chr "plotly-htmlwidgets-css"
#>   .. ..$ version   : chr "2.11.1"
#>   .. ..$ src       :List of 1
#>   .. .. ..$ file: chr "htmlwidgets/lib/plotlyjs"
#>   .. ..$ meta      : NULL
#>   .. ..$ script    : NULL
#>   .. ..$ stylesheet: chr "plotly-htmlwidgets.css"
#>   .. ..$ head      : NULL
#>   .. ..$ attachment: NULL
#>   .. ..$ package   : chr "plotly"
#>   .. ..$ all_files : logi FALSE
#>   .. ..- attr(*, "class")= chr "html_dependency"
#>   ..$ :List of 10
#>   .. ..$ name      : chr "plotly-main"
#>   .. ..$ version   : chr "2.11.1"
#>   .. ..$ src       :List of 1
#>   .. .. ..$ file: chr "htmlwidgets/lib/plotlyjs"
#>   .. ..$ meta      : NULL
#>   .. ..$ script    : chr "plotly-latest.min.js"
#>   .. ..$ stylesheet: NULL
#>   .. ..$ head      : NULL
#>   .. ..$ attachment: NULL
#>   .. ..$ package   : chr "plotly"
#>   .. ..$ all_files : logi FALSE
#>   .. ..- attr(*, "class")= chr "html_dependency"
#>  $ elementId    : NULL
#>  $ preRenderHook:function (p, registerFrames = TRUE)  
#>  $ jsHooks      : list()
#>  - attr(*, "class")= chr [1:2] "plotly" "htmlwidget"
#>  - attr(*, "package")= chr "plotly"
# the evaluated data
str(plotly_build(p)$x$data)
#> 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
#> List of 1
#>  $ :List of 11
#>   ..$ x      : Date[1:574], format: "1967-07-01" "1967-08-01" ...
#>   ..$ y      : num [1:574] 507 510 516 512 517 ...
#>   .. ..- attr(*, "apiSrc")= logi TRUE
#>   ..$ type   : chr "scatter"
#>   ..$ mode   : chr "markers"
#>   ..$ marker :List of 2
#>   .. ..$ color: 'colorway' chr "rgba(31,119,180,1)"
#>   .. ..$ line :List of 1
#>   .. .. ..$ color: 'colorway' chr "rgba(31,119,180,1)"
#>   ..$ error_y:List of 1
#>   .. ..$ color: 'colorway' chr "rgba(31,119,180,1)"
#>   ..$ error_x:List of 1
#>   .. ..$ color: 'colorway' chr "rgba(31,119,180,1)"
#>   ..$ line   :List of 1
#>   .. ..$ color: 'colorway' chr "rgba(31,119,180,1)"
#>   ..$ xaxis  : chr "x"
#>   ..$ yaxis  : chr "y"
#>   ..$ frame  : chr NA