Skip to content

Problem saving widget with custom html #239

Open
@johndharrison

Description

@johndharrison

I am trying to add custom html to an htmlwidget as per
https://cran.r-project.org/web/packages/htmlwidgets/vignettes/develop_advanced.html#custom-widget-html

To replicate the issue I have create a simple htmlwidget package with minimal code using

htmlwidgets::scaffoldWidget("mywidget")

I added some custom html for the widget johndharrison/simplewidget@23b38b3

The widget displays correctly and the custom html functions as expected. However htmlwidgets::saveWidget does not save the widget html as expected:

install.github("johndharrison/simplewidget")
library(simplewidget)
library(xml2)
library(magrittr)
sw <- simplewidget("hello, world")
tFile <- tempfile(fileext = ".html")
htmlwidgets::saveWidget(sw, file = tFile)
browseURL(tFile)
xml2::read_html(tFile) %>% 
  xml2::xml_find_all("//div[@id='htmlwidget_container']") %>% 
  as.character
[1] "<div id=\"htmlwidget_container\">\n<div>\n<pre><code>&lt;h1 id=\"someid\"&gt;My header&lt;/h1&gt;\n&lt;div id=\"htmlwidget-00d700b400000a3685d7\" style=\"width:960px;height:500px;\" class=\"simplewidget html-widget\"&gt;&lt;/div&gt;</code></pre>\n</div>\n</div>"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions