Py.Cafe

iisakkirotko/

solara-plotly-6-autosize

Exploring Iris Dataset with Plotly

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import plotly.express as px

import solara

df = px.data.iris()


@solara.component
def Page():
    with solara.VBox():
        fig = px.scatter(
            df,
            x="sepal_width",
            y="sepal_length",
            color="species"
        )
        fig_el = solara.FigurePlotly(
            fig
        )

        def autosize():
            fig_widget = solara.get_widget(fig_el)
            fig_widget.layout.autosize = True

        solara.use_effect(autosize, dependencies=[])