33# ' @param x a plotly object
44# ' @param ... additional arguments
55# ' @export
6- # ' @importFrom htmlwidgets createWidget
7- # ' @importFrom htmlwidgets sizingPolicy
8- print.plotly <- function (x , ... ) {
9- if (! inherits(x , " htmlwidget" )) x <- as.widget(x )
10- get(" print.htmlwidget" , envir = asNamespace(" htmlwidgets" ))(x , ... )
6+ print.plotly_hash <- function (x , ... ) {
7+ x <- as.widget(x )
8+ print(x , ... )
119}
1210
11+ # ' Print a 'built' plotly object
12+ # '
13+ # ' @param x a plotly object
14+ # ' @param ... additional arguments
15+ # ' @export
16+ print.plotly_built <- print.plotly_hash
17+
1318# ' Print a plotly object in a knitr doc
1419# '
1520# ' @param x a plotly object
1621# ' @param options knitr options.
1722# ' @param ... additional arguments
1823# ' @export
19- knit_print.plotly <- function (x , options , ... ) {
20- if ( ! inherits( x , " htmlwidget " )) x <- as.widget(x )
21- get( " knit_print.htmlwidget " , envir = asNamespace( " htmlwidgets " ))( x , options = options , ... )
24+ knit_print.plotly_hash <- function (x , options , ... ) {
25+ x <- as.widget(x )
26+ knitr :: knit_print( x , options , ... )
2227}
2328
29+ # ' Print a 'built' plotly object in a knitr doc
30+ # '
31+ # ' @param x a plotly object
32+ # ' @param ... additional arguments
33+ # ' @export
34+ knit_print.plotly_built <- knit_print.plotly_hash
35+
2436# ' Convert a plotly object to an htmlwidget object
2537# '
2638# ' @param x a plotly object.
@@ -34,22 +46,22 @@ knit_print.plotly <- function(x, options, ...) {
3446
3547as.widget <- function (x , ... ) {
3648 if (inherits(x , " htmlwidget" )) return (x )
37- p <- plotly_build(x )
49+ if ( ! inherits( x , " plotly_built " )) x <- plotly_build(x )
3850 # set some margin defaults if none are provided
39- p $ layout $ margin <- modifyList(
51+ x $ layout $ margin <- modifyList(
4052 list (b = 40 , l = 60 , t = 25 , r = 10 ),
41- p $ layout $ margin %|| % list ()
53+ x $ layout $ margin %|| % list ()
4254 )
43- p $ config $ modeBarButtonsToRemove <-
44- i(p $ config $ modeBarButtonsToRemove %|| % " sendDataToCloud" )
45- p $ base_url <- get_domain()
55+ x $ config $ modeBarButtonsToRemove <-
56+ i(x $ config $ modeBarButtonsToRemove %|| % " sendDataToCloud" )
57+ x $ base_url <- get_domain()
4658 # customize the JSON serializer (for htmlwidgets)
47- attr(p , ' TOJSON_FUNC' ) <- to_JSON
59+ attr(x , ' TOJSON_FUNC' ) <- to_JSON
4860 htmlwidgets :: createWidget(
4961 name = " plotly" ,
50- x = p ,
51- width = p $ width ,
52- height = p $ height ,
62+ x = x ,
63+ width = x $ width ,
64+ height = x $ height ,
5365 sizingPolicy = htmlwidgets :: sizingPolicy(
5466 padding = 5 ,
5567 browser.fill = TRUE
0 commit comments