Page layout when exporting to HTML from R with visNetwork

53 views Asked by At

I'm using the visNetwork package in R to export an HTML page with an interactive network. When I do this, the resulting page is structured with the interactive network displayed in a div, which is 960x500, positioned at 40x40. I'd like to determine the size of this before exporting so that I don't have to edit it manually in each exported file.

I render the interactive network in R with visInteractive(visNetwork(nodes,edges)); I can then export this either using visSave, or using RStudio's export function: screenshot of exporting as HTML from RStudio

The resulting page has padding 40px: Screenshot demonstrating 40px padding

And the network is in a 960x500 div: Screenshot demonstrating containing div

Which is inside a 1085x500 div: Screenshot demonstrating larger div

I want to embed these using an iframe on another site, so in this case I'd like the containing div to just be 100% x 100% - but generally, I can't see where this 960x500 gets determined before export. In the html file, these are determined here:

<script type="application/htmlwidget-sizing" data-for="htmlwidget-3bba27f42781c2932883">{"viewer":{"width":450,"height":350,"padding":15,"fill":true},"browser":{"width":960,"height":500,"padding":40,"fill":false}}</script>

Here's the full code for a toy example in R:

library(visNetwork);
nodes <- data.frame(id = 1:10, 
                    title = '<a target="_blank" href="https://github.com/datastorm-open/visNetwork">github</a>')
edges <- data.frame(from = round(runif(8)*10), to = round(runif(8)*10))
visNetwork(nodes, edges) %>%
    visInteraction(tooltipStyle = 'position: fixed;visibility:hidden;padding: 5px;white-space: nowrap;
 font-family: cursive;font-size:18px;font-color:purple;background-color: red;')

Here's the full code that R then exports (identical whether with visSave or RStudio export): https://codeshare.io/PdjbA7

How can I modify the layout of the HTML file when I export it?

0

There are 0 answers