ramnathv / htmlwidgets

HTML Widgets for R
http://htmlwidgets.org
Other
783 stars 207 forks source link

as.character.htmlwidget for integration of widgets in other html/htmlwidgets #268

Open timelyportfolio opened 7 years ago

timelyportfolio commented 7 years ago

htmlwidgets in a DT datatable

The popularity of my examples integrating sparkline and d3horizonR htmlwidgets into DT datatables led me to try to settle on a pattern for inclusion of any htmlwidget in datatable. While most of this discussion is DT-specific, I think one of the lessons I learned can serve as an improvement, so I will limit the discussion to this. The remainder of the discussion will continue at https://github.com/rstudio/DT/issues/410.

lesson - no as.character.htmlwidget

There might be a good reason for the lack of as.character.htmlwidget, such as encoding etc., but it seems this method could be helpful. I use it to aggregate with dplyr and store the character version of the htmlwidget as a column. Here is my first attempt. I am happy to submit a pull, but I wanted to vet the idea as an issue first.

as.character.htmlwidget <- function(x, ...) {
  htmltools::HTML(
    htmltools:::as.character.shiny.tag.list(
      htmlwidgets:::as.tags.htmlwidget(
        x
      ),
      ...
    )
  )
}
markschat commented 2 years ago

To join this discussion, I would love to see an exported version of

htmlwidgets:::toHTML(x)

As @timelyportfolio mentioned it is the only documented way (https://github.com/rstudio/DT/issues/410) to embed html widgets into eachother.

I use this approach to include plotly charts into a DT table within an R-Package and get a note on R CMD check - I follow a 0 note policy, so that bothers me a lot:

checking dependencies in R code ... NOTE
Unexported object imported by a ':::' call: ‘htmlwidgets:::toHTML’
See the note in ?`:::` about the use of this operator.

Thank´s for this amazing package btw! 🙏