reprex does not render code that uses ggplotly

Hi, trying to run reprex() with the following code:

library(tidyverse)
library(gapminder)
library(plotly)
p <- gapminder %>% 
  ggplot(aes(gdpPercap, lifeExp)) + 
  geom_point(aes(color = country), show.legend = FALSE)
ggplotly(p)

yields the following error:

Rendering reprex...
 
Error: callr subprocess failed: Functions that produce HTML output found in document targeting markdown_strict output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:

  always_allow_html: true

Note however that the HTML output will not be visible in non-HTML formats.

If I'm not using R markdown, is there still a way to fix this?

reprex uses RMarkdown under the hood in order to render its output.

1 Like

By default, reprex renders as markdown (which is why it shows up nicely formatted here, on SO, GitHub, etc.).

There is reprex(..., venue = "html"), but that wouldn't modify the YAML exactly as you're describing. I would, however, recommend giving that a whirl before digging in more deeply.

More details on venues, etc. in the README here:

The RMarkdown templates used in reprex are here.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

Thanks @mara, and do you know if there's a way of setting the YAML option for the under-the-hood Rmarkdown to always_allow_html: true, as the error suggests? I'm not where I would try to accomplish that.

Thanks again, @mara -- I'll post a question there.

After inquiring at https://github.com/tidyverse/reprex, the bottom line appears to be that ggplotly() is incompatible with reprex() since its output requires a full html environment for rendering. (See github issue here.)

1 Like