3

I am writing a Quarto markdown file containing both Python and R code. With python, I have a bunch of lines that use Plotly to make interactive plots. However, instead of showing the charts in the output cell of the quarto file, my script always opens the browser and renders the chart. This is not desirable because the plots are missing from the rendered HTML file when we try to render the entire quarto markdown script.

Can someone tell me if it is possible to render the plotly outputs inside the qmd files?

Thanks.

1 Answer 1

0

One way to get this done is by loading the chart through R. The following .qmd document is displaying the figure in the viewer and in the final document.

---
title: "test-plotly"
format: html
editor: visual
---

```{python}
import numpy as np
import plotly.graph_objects as go
import plotly as pl

N = 100
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
sz = np.random.rand(N) * 30

fig = go.Figure()
fig.add_trace(go.Scatter(
    x=x,
    y=y,
    mode="markers",
    marker=go.scatter.Marker(
        size=sz,
        color=colors,
        opacity=0.6,
        colorscale="Viridis"
    )
))

file = 'plot.html'
pl.io.write_html(fig, file=file, auto_open=False)
```

```{r}
htmltools::includeHTML(py$file)
```

Rstudio version is 2022.07.1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.