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?
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.
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.
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With