import altair as alt
import pandas as pd
import solara
import solara.lab
df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
chart = (
alt.Chart(df)
.mark_point()
.encode(
x="x",
y="y",
)
)
@solara.component
def Option1():
with solara.AppBar():
solara.solara.lab.ThemeToggle()
dark_effective = solara.lab.use_dark_effective()
dark_effective_previous = solara.use_previous(dark_effective)
# uncomment this and the theme toggle no longer works
solara.Text(str(dark_effective))
if dark_effective != dark_effective_previous:
if dark_effective:
alt.themes.enable("dark")
else:
alt.themes.enable("default")
solara.FigureAltair(chart).key(f"chart-{dark_effective}")
@solara.component
def Option2():
dark_effective = solara.lab.use_dark_effective()
if dark_effective:
options = {"actions": False, "theme": "dark"}
else:
options = {"actions": False}
jchart = alt.JupyterChart.element(chart=chart, embed_options=options) # type: ignore
@solara.component
def Page():
with solara.Row():
Option1()
Option2()