-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29935be
commit 6f2487f
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""# FigureAltair | ||
""" | ||
|
||
import altair as alt | ||
import pandas as pd | ||
|
||
import solara | ||
from solara.website.utils import apidoc | ||
|
||
title = "FigureAltair" | ||
|
||
df = pd.DataFrame({"a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"], "b": [28, 55, 43, 91, 81, 53, 19, 87, 52]}) | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
click_data, set_click_data = solara.use_state(None) | ||
hover_data, set_hover_data = solara.use_state(None) | ||
|
||
chart = alt.Chart(df).mark_bar().encode(x="a", y="b") | ||
|
||
with solara.Div() as main: | ||
solara.AltairChart(chart, on_click=set_click_data, on_hover=set_hover_data) | ||
|
||
solara.Markdown( | ||
f""" | ||
Click data: | ||
``` | ||
{click_data} | ||
``` | ||
Hover data: | ||
``` | ||
{hover_data} | ||
``` | ||
""" | ||
) | ||
|
||
return main | ||
|
||
|
||
__doc__ += apidoc(solara.FigureAltair.f) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""# Scatter plot using Plotly | ||
This example shows how to use Plotly to create a scatter plot and a slider to do some filtering. | ||
Inspired by the dash documentation. | ||
## Note | ||
Solara supports plotly and plotly express. Create your figure (not a figure widget) | ||
and pass it to the [FigurePlotly](/api/plotly) component. | ||
""" | ||
import pandas as pd | ||
import plotly.express as px | ||
|
||
import solara | ||
|
||
title = "Scatter plot using Plotly" | ||
|
||
try: | ||
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv") | ||
except Exception: | ||
df = None | ||
|
||
if df is not None: | ||
year_min = df["year"].min() | ||
year_max = df["year"].max() | ||
years = df["year"].unique().tolist() | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
with solara.Div() as main: | ||
index = solara.ui_slider(value=0, min=0, max=len(years) - 1, tick_labels=years, key="year slider index") | ||
selected_year = years[index] | ||
|
||
filtered_df = df[df.year == selected_year].copy() | ||
|
||
fig = px.scatter(filtered_df, x="gdpPercap", y="lifeExp", size="pop", color="continent", hover_name="country", log_x=True, size_max=55) | ||
fig.update_layout(transition_duration=1500) | ||
|
||
solara.FigurePlotly(fig, dependencies=[selected_year]) | ||
return main |