Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize HTML widget using saveWidget in htmlwidgets R?

Tags:

r

htmlwidgets

I use saveWidget function in htmlwidgets to save HTML widgets in R. I got the saved HTML files with width 960 and height 500. I am pretty sure that I can resize the widget within knitrOptions parameters but I can not find out the list of the parameters to resize the widget. I have tried:

library(htmlwidgets)
saveWidget(htmlplot, file, knitrOptions = list(width = 1200, height = 700)

I also have tried using fig.width, defaultWidth, etc. but none of them are worked.

How could I resize the widget?

like image 252
rasyidstat Avatar asked Dec 21 '17 09:12

rasyidstat


People also ask

How do I change the size of a widget in HTML?

To adjust the dimensions of the widget, add a style div to the code surrounding your widget. This step is done with HTML, making the widget frame appearance fully customizable.

What is an HTML widget in R?

The htmlwidgets package provides a framework for creating R bindings to JavaScript libraries. HTML Widgets can be: Used at the R console for data analysis just like conventional R plots. Embedded within R Markdown documents. Incorporated into Shiny web applications.


1 Answers

I had this problem today. Unfortunately, I didn't find a good solution to this. I had to change the attribute width of the widget:

wid <- ggiraph(ggobj=pl,
               zoom_max=1000,
               tooltip_opacity=0.7,
               tooltip_extra_css="width:300px;background-color:black;color:white;font-family:Sans,Arial",
               width_svg=80,
               height_svg=7,
               width=1)
wid$x$width <- "6000px"
temp_output <- tempfile(tmpdir=getwd(), fileext=".html")
saveWidget(widget=wid, file=basename(temp_output), selfcontained=TRUE,
           knitrOptions=list())
like image 188
matheuscburger Avatar answered Sep 20 '22 11:09

matheuscburger