insightsengineering / teal.reporter

Create and preview reports with Shiny modules
https://insightsengineering.github.io/teal.reporter/
Other
8 stars 9 forks source link

[Feature Request]: Allow htmlwidgets Plots in Report #129

Open armcn opened 2 years ago

armcn commented 2 years ago

Feature description

The append_plot method doesn't support htmlwidgets like plotly. This would be very useful because plotly is heavily utilized in pharma shiny apps.

Code of Conduct

Contribution Guidelines

Security Policy

Polkas commented 2 years ago

Thank you for the response, we will assess it shortly.

The best idea is to create a new internal Block (like widgetBlock) and the linked append method which will cache any widgets content with:

htmlwidgets::saveWidget(widget =, file = )
webshot::webshot(url =  file = )
Polkas commented 2 years ago

@armcn there is already a way to support plotly in many scenarios (I know it is NOT cover all). Very often the plotly plot is build over the regular ggplot with the ggplotly function. Then to the app output you still pass what is returned by ggplotly but to the teal.reporter you pass the base ggplot object.

library(plotly)
library(ggplot2)

set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]

# pass to the teal.reporter
p <- ggplot(data = d, aes(x = carat, y = price)) +
  geom_point(aes(text = paste("Clarity:", clarity)), size = 4) +
  geom_smooth(aes(colour = cut, fill = cut)) + facet_wrap(~ cut)

# pass to the shiny output
ggplotly(p)
asbates commented 2 years ago

For plotly without ggplot2 there is also plotly::save_image but it needs an additional python package.