0

I am generating reports using r-markdown, knitr, ggplot and plotly. My plot objects are passed in as parameters. I can generate ggplot output thus:

```{r echo = FALSE}
plot(params$plot_id__0_1)
```

However, if I try the same with a plotly object it fails (Error in xy.coords: 'x' is a list, but does not have components 'x' and 'y'):

```{r plotly = TRUE}
plot(params$plot_id__0_2)
```

I have seen r-markdown where plotly objects are evaulated in-place, so I have tried:

```{r plotly = TRUE}
params$plot_id__0_2
```

but I just get the text output "params$plot_id__0_2".

So the question is: how do I get my plotly output displayed in the report when the plotly object is input as a parameter? (I have included the ggplot2 and plotly packages in the markdown.)

Thanks for any advice.

jxf
  • 163
  • 1
  • 9

1 Answers1

0

The magic is:

```{r echo = FALSE}
htmltools::tagList(params$plot_id__0_2)
```

Thanks to parth in reponse to this post.

The task was made more difficult as Firefox (49.0.1 and 50.1.0), Windows 7 and plotly don't play nicely (at least not on my machine). In this combination, the plots appeared blank, but it works fine with Chrome.

jxf
  • 163
  • 1
  • 9