Skip to content

Commit

Permalink
Rollback giles
Browse files Browse the repository at this point in the history
  • Loading branch information
itepifanio committed Oct 2, 2023
1 parent 29935be commit 6f2487f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion solara/website/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from solara.alias import rv
from solara.components.title import Title

#from ..components import Header, Hero
from ..components import Header, Hero


title = "Home"
Expand Down
44 changes: 44 additions & 0 deletions solara/website/pages/api/altair.py
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
44 changes: 44 additions & 0 deletions solara/website/pages/examples/visualization/plotly.py
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

0 comments on commit 6f2487f

Please sign in to comment.