Spaces:
Sleeping
Sleeping
solara plotly graphs init
Browse files- .gitignore +1 -0
- Dockerfile +2 -2
- pages/00_home.py +0 -101
- pages/animated.py +45 -0
- pages/bar.py +73 -0
- pages/boxs.py +97 -0
- pages/density_heatmap.py +56 -0
- pages/histogram.py +72 -0
- pages/line.py +184 -0
- pages/main.py +105 -0
- pages/maps.py +96 -0
- pages/other_plot.py +105 -0
- pages/pie.py +61 -0
- pages/scatter.py +155 -0
- pages/treed_plot.py +48 -0
- pages/utils.py +20 -0
- pages/violin.py +84 -0
- requirements.txt +2 -1
.gitignore
CHANGED
|
@@ -137,6 +137,7 @@ venv.bak/
|
|
| 137 |
|
| 138 |
# mkdocs documentation
|
| 139 |
/site
|
|
|
|
| 140 |
|
| 141 |
# mypy
|
| 142 |
.mypy_cache/
|
|
|
|
| 137 |
|
| 138 |
# mkdocs documentation
|
| 139 |
/site
|
| 140 |
+
.history/
|
| 141 |
|
| 142 |
# mypy
|
| 143 |
.mypy_cache/
|
Dockerfile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
FROM jupyter/base-notebook:latest
|
| 2 |
|
| 3 |
-
RUN mamba install -c conda-forge
|
| 4 |
fix-permissions "${CONDA_DIR}" && \
|
| 5 |
fix-permissions "/home/${NB_USER}"
|
| 6 |
|
|
@@ -18,4 +18,4 @@ USER ${NB_USER}
|
|
| 18 |
|
| 19 |
EXPOSE 8765
|
| 20 |
|
| 21 |
-
CMD ["solara", "run", "./pages", "--host=0.0.0.0"]
|
|
|
|
| 1 |
FROM jupyter/base-notebook:latest
|
| 2 |
|
| 3 |
+
RUN mamba install -c conda-forge geopandas localtileserver -y && \
|
| 4 |
fix-permissions "${CONDA_DIR}" && \
|
| 5 |
fix-permissions "/home/${NB_USER}"
|
| 6 |
|
|
|
|
| 18 |
|
| 19 |
EXPOSE 8765
|
| 20 |
|
| 21 |
+
CMD ["solara", "run", "./pages/main.py", "--host=0.0.0.0"]
|
pages/00_home.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 1 |
-
from typing import Optional, cast
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import os
|
| 4 |
-
import solara
|
| 5 |
-
from solara.components.file_drop import FileDrop
|
| 6 |
-
from lat_lon_parser import parse,to_str_deg_min_sec
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
class State:
|
| 10 |
-
options = ["Decimal", "Deg_Min_Sec"]
|
| 11 |
-
option = solara.reactive("")
|
| 12 |
-
df = solara.reactive(cast(Optional[pd.DataFrame], None))
|
| 13 |
-
dff = solara.reactive(cast(Optional[pd.DataFrame], None))
|
| 14 |
-
latitude = solara.reactive(cast(Optional[str],""))
|
| 15 |
-
longitude = solara.reactive(cast(Optional[str],""))
|
| 16 |
-
extension_check = solara.reactive(True)
|
| 17 |
-
error_message = solara.reactive("")
|
| 18 |
-
|
| 19 |
-
@staticmethod
|
| 20 |
-
def load_from_file(file):
|
| 21 |
-
file_name, file_extension = os.path.splitext(file["name"])
|
| 22 |
-
if file_extension == ".csv":
|
| 23 |
-
df = pd.read_csv(file["file_obj"], encoding='latin-1')
|
| 24 |
-
State.df.value = df
|
| 25 |
-
State.extension_check.value = True
|
| 26 |
-
State.reset_vars()
|
| 27 |
-
else:
|
| 28 |
-
State.extension_check.value = False
|
| 29 |
-
State.df.value = None
|
| 30 |
-
State.reset_vars()
|
| 31 |
-
|
| 32 |
-
def reset_vars():
|
| 33 |
-
State.latitude.value = str("")
|
| 34 |
-
State.longitude.value = str("")
|
| 35 |
-
State.option.value = str("")
|
| 36 |
-
State.error_message.value =str("")
|
| 37 |
-
|
| 38 |
-
@staticmethod
|
| 39 |
-
def convert ():
|
| 40 |
-
State.error_message.value =""
|
| 41 |
-
try :
|
| 42 |
-
df = State.df.value
|
| 43 |
-
df['converted_latitude'] = df.loc[:, str(State.latitude.value)]
|
| 44 |
-
df['converted_longitude'] = df.loc[:, str(State.longitude.value)]
|
| 45 |
-
if State.option.value =="Decimal":
|
| 46 |
-
df['converted_longitude'] =df['converted_longitude'].str.replace('O','W')
|
| 47 |
-
df["converted_latitude"] =df["converted_latitude"].apply(parse)
|
| 48 |
-
df["converted_longitude"] =df["converted_longitude"].apply(parse)
|
| 49 |
-
elif State.option.value =="Deg_Min_Sec":
|
| 50 |
-
df["converted_latitude"] =df["converted_latitude"].apply(to_str_deg_min_sec)
|
| 51 |
-
df["converted_longitude"] =df["converted_longitude"].apply(to_str_deg_min_sec)
|
| 52 |
-
df["converted_latitude"] =df["converted_latitude"].apply(lambda x: x.replace("-", "") + "S" if "-" in x else x + "N")
|
| 53 |
-
df["converted_longitude"] =df["converted_longitude"].apply(lambda x: x.replace("-", "") + "W" if "-" in x else x + "E")
|
| 54 |
-
except Exception as es:
|
| 55 |
-
State.error_message.value = f"An error occurred. Please check your latitude and longitude format and ensure the correct conversion format ({es})"
|
| 56 |
-
else :
|
| 57 |
-
State.df.value = None
|
| 58 |
-
State.df.value = df
|
| 59 |
-
State.dff.value = State.df.value
|
| 60 |
-
|
| 61 |
-
@solara.component
|
| 62 |
-
def Page():
|
| 63 |
-
df = State.df.value
|
| 64 |
-
|
| 65 |
-
solara.Title("GPS Coordinates Converter")
|
| 66 |
-
|
| 67 |
-
with solara.Sidebar():
|
| 68 |
-
with solara.Column():
|
| 69 |
-
FileDrop(on_file=State.load_from_file, on_total_progress=lambda *args: None, label="Drag your file CSV here")
|
| 70 |
-
|
| 71 |
-
if State.extension_check.value is not True :
|
| 72 |
-
solara.Warning("Only CSV file are allowed")
|
| 73 |
-
else :
|
| 74 |
-
if df is not None:
|
| 75 |
-
columns = list(map(str, df.columns))
|
| 76 |
-
solara.Select("Latitude", values=columns, value=State.latitude)
|
| 77 |
-
solara.Select("Longitude", values=columns, value=State.longitude)
|
| 78 |
-
solara.Select("Convert To", values=State.options, value=State.option)
|
| 79 |
-
|
| 80 |
-
if State.longitude.value =="" or State.latitude.value == "" or State.option.value == "":
|
| 81 |
-
solara.Info("Select Coordinates Columns and Ouput Format")
|
| 82 |
-
else :
|
| 83 |
-
solara.Button("Convert", color="primary", text=True, outlined=True, on_click=State.convert)
|
| 84 |
-
if State.dff.value is not None:
|
| 85 |
-
def get_data():
|
| 86 |
-
return State.dff.value.to_csv(index=False)
|
| 87 |
-
solara.FileDownload(get_data, label=f"Download {len(State.dff.value):,} converted coordinates", filename="converted.csv",)
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
if State.df.value is not None:
|
| 91 |
-
with solara.Column():
|
| 92 |
-
solara.DataFrame(State.df.value)
|
| 93 |
-
if State.error_message.value != "":
|
| 94 |
-
solara.Warning(State.error_message.value)
|
| 95 |
-
else:
|
| 96 |
-
solara.Info("Waiting for Data, Please upload a file.")
|
| 97 |
-
|
| 98 |
-
@solara.component
|
| 99 |
-
def Layout(children):
|
| 100 |
-
route, routes = solara.use_route()
|
| 101 |
-
return solara.AppLayout(children=children)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/animated.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
from utils import selected_template
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@solara.component
|
| 8 |
+
def AnimatedPlots():
|
| 9 |
+
|
| 10 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 11 |
+
|
| 12 |
+
solara.Markdown(f"#Animated Plots")
|
| 13 |
+
# Create an animated plot that you can use to cycle through continent
|
| 14 |
+
# GDP & life expectancy changes
|
| 15 |
+
df_cnt = px.data.gapminder()
|
| 16 |
+
fig1= px.scatter(df_cnt, x="gdpPercap", y="lifeExp", animation_frame="year",
|
| 17 |
+
animation_group="country",
|
| 18 |
+
template=selected_template.value,
|
| 19 |
+
size="pop", color="continent", hover_name="country",
|
| 20 |
+
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
|
| 21 |
+
|
| 22 |
+
# Watch as bars chart population changes
|
| 23 |
+
fig2 =px.bar(df_cnt, x="continent", y="pop", color="continent",template=selected_template.value,
|
| 24 |
+
animation_frame="year", animation_group="country", range_y=[0,4000000000])
|
| 25 |
+
|
| 26 |
+
solara.Markdown("""
|
| 27 |
+
```python
|
| 28 |
+
# Create an animated plot that you can use to cycle through continent
|
| 29 |
+
# GDP & life expectancy changes
|
| 30 |
+
df_cnt = px.data.gapminder()
|
| 31 |
+
px.scatter(df_cnt, x="gdpPercap", y="lifeExp", animation_frame="year",
|
| 32 |
+
animation_group="country",
|
| 33 |
+
size="pop", color="continent", hover_name="country",
|
| 34 |
+
log_x=True, size_max=55, range_x=[100,100000], range_y=[25,90])
|
| 35 |
+
|
| 36 |
+
# Watch as bars chart population changes
|
| 37 |
+
px.bar(df_cnt, x="continent", y="pop", color="continent",
|
| 38 |
+
animation_frame="year", animation_group="country", range_y=[0,4000000000])
|
| 39 |
+
```
|
| 40 |
+
"""
|
| 41 |
+
)
|
| 42 |
+
solara.display(fig1)
|
| 43 |
+
solara.display(fig2)
|
| 44 |
+
|
| 45 |
+
return main
|
pages/bar.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
from utils import selected_template
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@solara.component
|
| 7 |
+
def BarPlot():
|
| 8 |
+
with solara.Column(gap="10px",align="stretch" ) as main:
|
| 9 |
+
solara.Markdown(f"#BAR PLOTS")
|
| 10 |
+
# Get population change in US by querying for US data
|
| 11 |
+
df_us = px.data.gapminder().query("country == 'United States'")
|
| 12 |
+
fig1 = px.bar(df_us, x='year', y='pop',template=selected_template.value)
|
| 13 |
+
solara.FigurePlotly(fig1)
|
| 14 |
+
|
| 15 |
+
# Create a stacked bar with more customization
|
| 16 |
+
df_tips = px.data.tips()
|
| 17 |
+
fig2 = px.bar(df_tips, x='day', y='tip', color='sex', title='Tips by Sex on Each Day',template=selected_template.value,
|
| 18 |
+
labels={'tip': 'Tip Amount', 'day': 'Day of the Week'})
|
| 19 |
+
solara.Markdown(f"###Create a stacked bar with more customization")
|
| 20 |
+
solara.Markdown("""
|
| 21 |
+
```python
|
| 22 |
+
fig2 = px.bar(df_tips, x='day', y='tip', color='sex', title='Tips by Sex on Each Day',
|
| 23 |
+
labels={'tip': 'Tip Amount', 'day': 'Day of the Week'})
|
| 24 |
+
```
|
| 25 |
+
"""
|
| 26 |
+
)
|
| 27 |
+
solara.FigurePlotly(fig2)
|
| 28 |
+
|
| 29 |
+
# Place bars next to each other
|
| 30 |
+
fig3 = px.bar(df_tips, x="sex", y="total_bill",template=selected_template.value,
|
| 31 |
+
color='smoker', barmode='group')
|
| 32 |
+
solara.Markdown(f"###Place bars next to each other")
|
| 33 |
+
solara.Markdown("""
|
| 34 |
+
```python
|
| 35 |
+
fig3 = px.bar(df_tips, x="sex", y="total_bill",
|
| 36 |
+
color='smoker', barmode='group')
|
| 37 |
+
```
|
| 38 |
+
"""
|
| 39 |
+
)
|
| 40 |
+
solara.FigurePlotly(fig3)
|
| 41 |
+
|
| 42 |
+
# Display pop data for countries in Europe in 2007 greater than 2000000
|
| 43 |
+
df_europe = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
|
| 44 |
+
fig4 = px.bar(df_europe, y='pop', x='country', text='pop', color='country',template=selected_template.value)
|
| 45 |
+
# Put bar total value above bars with 2 values of precision
|
| 46 |
+
fig4.update_traces(texttemplate='%{text:.2s}', textposition='outside')
|
| 47 |
+
# Set fontsize and uniformtext_mode='hide' says to hide the text if it won't fit
|
| 48 |
+
fig4.update_layout(uniformtext_minsize=8)
|
| 49 |
+
# Rotate labels 45 degrees
|
| 50 |
+
fig4.update_layout(xaxis_tickangle=-45)
|
| 51 |
+
|
| 52 |
+
solara.Markdown(f"###Display pop data for countries in Europe in 2007 greater than 2000000")
|
| 53 |
+
solara.Markdown("""
|
| 54 |
+
```python
|
| 55 |
+
df_europe = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 2.e6")
|
| 56 |
+
fig4 = px.bar(df_europe, y='pop', x='country', text='pop', color='country')
|
| 57 |
+
# Put bar total value above bars with 2 values of precision
|
| 58 |
+
fig4.update_traces(texttemplate='%{text:.2s}', textposition='outside')
|
| 59 |
+
# Set fontsize and uniformtext_mode='hide' says to hide the text if it won't fit
|
| 60 |
+
fig4.update_layout(uniformtext_minsize=8)
|
| 61 |
+
# Rotate labels 45 degrees
|
| 62 |
+
fig4.update_layout(xaxis_tickangle=-45)
|
| 63 |
+
```
|
| 64 |
+
"""
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
solara.FigurePlotly(fig4)
|
| 70 |
+
|
| 71 |
+
return main
|
| 72 |
+
|
| 73 |
+
|
pages/boxs.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@solara.component
|
| 9 |
+
def Boxs():
|
| 10 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 11 |
+
|
| 12 |
+
solara.Markdown(f"#BOX PLOTS")
|
| 13 |
+
|
| 14 |
+
# A box plot allows you to compare different variables
|
| 15 |
+
# The box shows the quartiles of the data. The bar in the middle is the median
|
| 16 |
+
# The whiskers extend to all the other data aside from the points that are considered
|
| 17 |
+
# to be outliers
|
| 18 |
+
df_tips = px.data.tips()
|
| 19 |
+
# We can see which sex tips the most, points displays all the data points
|
| 20 |
+
fig1= px.box(df_tips, x='sex', y='tip', points='all', template= selected_template.value)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Display tip sex data by day
|
| 24 |
+
fig2=px.box(df_tips, x='day', y='tip', color='sex', template= selected_template.value)
|
| 25 |
+
|
| 26 |
+
# Adding standard deviation and mean
|
| 27 |
+
fig3 = go.Figure()
|
| 28 |
+
fig3.add_trace(go.Box(x=df_tips.sex, y=df_tips.tip, marker_color='blue',
|
| 29 |
+
boxmean='sd'))
|
| 30 |
+
fig3.update_layout(template= selected_template.value)
|
| 31 |
+
|
| 32 |
+
solara.Markdown(f"#### Use Box plot to compare different variables ")
|
| 33 |
+
solara.Markdown("""
|
| 34 |
+
```python
|
| 35 |
+
# A box plot allows you to compare different variables
|
| 36 |
+
# The box shows the quartiles of the data. The bar in the middle is the median
|
| 37 |
+
# The whiskers extend to all the other data aside from the points that are considered
|
| 38 |
+
# to be outliers
|
| 39 |
+
df_tips = px.data.tips()
|
| 40 |
+
# We can see which sex tips the most, points displays all the data points
|
| 41 |
+
px.box(df_tips, x='sex', y='tip', points='all')
|
| 42 |
+
|
| 43 |
+
# Display tip sex data by day
|
| 44 |
+
px.box(df_tips, x='day', y='tip', color='sex')
|
| 45 |
+
|
| 46 |
+
# Adding standard deviation and mean
|
| 47 |
+
fig1 = go.Figure()
|
| 48 |
+
fig1.add_trace(go.Box(x=df_tips.sex, y=df_tips.tip, marker_color='blue',
|
| 49 |
+
boxmean='sd'))
|
| 50 |
+
```
|
| 51 |
+
"""
|
| 52 |
+
)
|
| 53 |
+
solara.FigurePlotly(fig1)
|
| 54 |
+
solara.FigurePlotly(fig2)
|
| 55 |
+
solara.FigurePlotly(fig3)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# Complex Styling
|
| 59 |
+
df_stocks = px.data.stocks()
|
| 60 |
+
fig4 = go.Figure()
|
| 61 |
+
# Show all points, spread them so they don't overlap and change whisker width
|
| 62 |
+
fig4.add_trace(go.Box(y=df_stocks.GOOG, boxpoints='all', name='Google',
|
| 63 |
+
fillcolor='blue', jitter=0.5, whiskerwidth=0.2))
|
| 64 |
+
fig4.add_trace(go.Box(y=df_stocks.AAPL, boxpoints='all', name='Apple',
|
| 65 |
+
fillcolor='red', jitter=0.5, whiskerwidth=0.2))
|
| 66 |
+
# Change background / grid colors
|
| 67 |
+
fig4.update_layout(title='Google vs. Apple',
|
| 68 |
+
yaxis=dict(gridcolor='rgb(255, 255, 255)',
|
| 69 |
+
gridwidth=3),template= selected_template.value,
|
| 70 |
+
paper_bgcolor='rgb(243, 243, 243)',
|
| 71 |
+
plot_bgcolor='rgb(243, 243, 243)'
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
# fig4.update_layout(template= selected_template.value)
|
| 75 |
+
solara.Markdown(f"####Complex Styling")
|
| 76 |
+
solara.Markdown("""
|
| 77 |
+
```python
|
| 78 |
+
# Complex Styling
|
| 79 |
+
df_stocks = px.data.stocks()
|
| 80 |
+
fig2 = go.Figure()
|
| 81 |
+
# Show all points, spread them so they don't overlap and change whisker width
|
| 82 |
+
fig2.add_trace(go.Box(y=df_stocks.GOOG, boxpoints='all', name='Google',
|
| 83 |
+
fillcolor='blue', jitter=0.5, whiskerwidth=0.2))
|
| 84 |
+
fig2.add_trace(go.Box(y=df_stocks.AAPL, boxpoints='all', name='Apple',
|
| 85 |
+
fillcolor='red', jitter=0.5, whiskerwidth=0.2))
|
| 86 |
+
# Change background / grid colors
|
| 87 |
+
fig2.update_layout(title='Google vs. Apple',
|
| 88 |
+
yaxis=dict(gridcolor='rgb(255, 255, 255)',
|
| 89 |
+
gridwidth=3),
|
| 90 |
+
paper_bgcolor='rgb(243, 243, 243)',
|
| 91 |
+
plot_bgcolor='rgb(243, 243, 243)')
|
| 92 |
+
```
|
| 93 |
+
"""
|
| 94 |
+
)
|
| 95 |
+
solara.FigurePlotly(fig4)
|
| 96 |
+
|
| 97 |
+
return main
|
pages/density_heatmap.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import seaborn as sns
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@solara.component
|
| 8 |
+
def DensityHeatmap():
|
| 9 |
+
|
| 10 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 11 |
+
|
| 12 |
+
solara.Markdown(f"#Density Heatmap")
|
| 13 |
+
# Create a heatmap using Seaborn data
|
| 14 |
+
flights = sns.load_dataset("flights")
|
| 15 |
+
flights
|
| 16 |
+
|
| 17 |
+
# You can set bins with nbinsx and nbinsy
|
| 18 |
+
fig1 = px.density_heatmap(flights, x='year', y='month', z='passengers',
|
| 19 |
+
color_continuous_scale="Viridis",
|
| 20 |
+
template=selected_template.value)
|
| 21 |
+
|
| 22 |
+
solara.Markdown(f"####Create a heatmap using Seaborn data")
|
| 23 |
+
|
| 24 |
+
solara.Markdown("""
|
| 25 |
+
```python
|
| 26 |
+
# Create a heatmap using Seaborn data
|
| 27 |
+
flights = sns.load_dataset("flights")
|
| 28 |
+
flights
|
| 29 |
+
|
| 30 |
+
# You can set bins with nbinsx and nbinsy
|
| 31 |
+
fig1 = px.density_heatmap(flights, x='year', y='month', z='passengers',
|
| 32 |
+
color_continuous_scale="Viridis")
|
| 33 |
+
```
|
| 34 |
+
"""
|
| 35 |
+
)
|
| 36 |
+
solara.FigurePlotly(fig1)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# You can add histograms
|
| 41 |
+
fig2 = px.density_heatmap(flights, x='year', y='month', z='passengers',
|
| 42 |
+
marginal_x="histogram", marginal_y="histogram",
|
| 43 |
+
template=selected_template.value)
|
| 44 |
+
|
| 45 |
+
solara.Markdown(f"####Add histograms")
|
| 46 |
+
solara.Markdown("""
|
| 47 |
+
```python
|
| 48 |
+
# You can add histograms
|
| 49 |
+
fig2 = px.density_heatmap(flights, x='year', y='month', z='passengers',
|
| 50 |
+
marginal_x="histogram", marginal_y="histogram")
|
| 51 |
+
```
|
| 52 |
+
"""
|
| 53 |
+
)
|
| 54 |
+
solara.FigurePlotly(fig2)
|
| 55 |
+
|
| 56 |
+
return main
|
pages/histogram.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import numpy as np
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@solara.component
|
| 8 |
+
def Histograms():
|
| 9 |
+
|
| 10 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 11 |
+
|
| 12 |
+
solara.Markdown(f"#HISTOGRAMS")
|
| 13 |
+
|
| 14 |
+
# Plot histogram based on rolling 2 dice
|
| 15 |
+
dice_1 = np.random.randint(1,7,5000)
|
| 16 |
+
dice_2 = np.random.randint(1,7,5000)
|
| 17 |
+
dice_sum = dice_1 + dice_2
|
| 18 |
+
# bins represent the number of bars to make
|
| 19 |
+
# Can define x label, color, title
|
| 20 |
+
# marginal creates another plot (violin, box, rug)
|
| 21 |
+
fig1 = px.histogram(dice_sum, nbins=11, labels={'value':'Dice Roll'},
|
| 22 |
+
title='5000 Dice Roll Histogram', marginal='violin',
|
| 23 |
+
color_discrete_sequence=['green'])
|
| 24 |
+
|
| 25 |
+
fig1.update_layout(
|
| 26 |
+
xaxis_title_text='Dice Roll',
|
| 27 |
+
yaxis_title_text='Dice Sum',
|
| 28 |
+
bargap=0.2, showlegend=False,
|
| 29 |
+
template=selected_template.value
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
solara.Markdown(f"#### Plot histogram based on rolling 2 dice ")
|
| 33 |
+
solara.Markdown("""
|
| 34 |
+
```python
|
| 35 |
+
dice_1 = np.random.randint(1,7,5000)
|
| 36 |
+
dice_2 = np.random.randint(1,7,5000)
|
| 37 |
+
dice_sum = dice_1 + dice_2
|
| 38 |
+
# bins represent the number of bars to make
|
| 39 |
+
# Can define x label, color, title
|
| 40 |
+
# marginal creates another plot (violin, box, rug)
|
| 41 |
+
fig1 = px.histogram(dice_sum, nbins=11, labels={'value':'Dice Roll'},
|
| 42 |
+
title='5000 Dice Roll Histogram', marginal='violin',
|
| 43 |
+
color_discrete_sequence=['green'])
|
| 44 |
+
|
| 45 |
+
fig1.update_layout(
|
| 46 |
+
xaxis_title_text='Dice Roll',
|
| 47 |
+
yaxis_title_text='Dice Sum',
|
| 48 |
+
bargap=0.2, showlegend=False
|
| 49 |
+
)
|
| 50 |
+
```
|
| 51 |
+
"""
|
| 52 |
+
)
|
| 53 |
+
solara.FigurePlotly(fig1)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Stack histograms based on different column data
|
| 58 |
+
df_tips = px.data.tips()
|
| 59 |
+
fig2= px.histogram(df_tips, x="total_bill", color="sex",template=selected_template.value)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
solara.Markdown(f"####Stack histograms based on different column data")
|
| 63 |
+
solara.Markdown("""
|
| 64 |
+
```python
|
| 65 |
+
df_tips = px.data.tips()
|
| 66 |
+
px.histogram(df_tips, x="total_bill", color="sex")
|
| 67 |
+
```
|
| 68 |
+
"""
|
| 69 |
+
)
|
| 70 |
+
solara.FigurePlotly(fig2)
|
| 71 |
+
|
| 72 |
+
return main
|
pages/line.py
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
@solara.component
|
| 7 |
+
def LinePlot():
|
| 8 |
+
|
| 9 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 10 |
+
|
| 11 |
+
solara.Markdown(f"#LINE PLOTS")
|
| 12 |
+
|
| 13 |
+
df_stocks = px.data.stocks()
|
| 14 |
+
fig1 = px.line(df_stocks, x='date', y='GOOG', labels={'x':'Date', 'y':'Price'},
|
| 15 |
+
template=selected_template.value
|
| 16 |
+
)
|
| 17 |
+
solara.Markdown(f"###Use included Google price data to make one plot")
|
| 18 |
+
|
| 19 |
+
solara.Markdown("""
|
| 20 |
+
```python
|
| 21 |
+
fig1 = px.line(df_stocks, x='date', y='GOOG', labels={'x':'Date', 'y':'Price'},
|
| 22 |
+
template=selection_data.value)
|
| 23 |
+
```
|
| 24 |
+
"""
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
solara.FigurePlotly(fig1)
|
| 30 |
+
|
| 31 |
+
all_stocks =df_stocks.columns.values.tolist()
|
| 32 |
+
del all_stocks[0]
|
| 33 |
+
stocks,set_stocks = solara.use_state ([all_stocks[0],all_stocks[1]])
|
| 34 |
+
|
| 35 |
+
fig2 = px.line(df_stocks, x='date', y=stocks, labels={'x':'Date', 'y':'Price'},
|
| 36 |
+
title=" VS ".join(stocks),
|
| 37 |
+
template=selected_template.value)
|
| 38 |
+
|
| 39 |
+
with solara.Card():
|
| 40 |
+
solara.Markdown(f"###Make multiple line plots")
|
| 41 |
+
|
| 42 |
+
solara.Markdown("""
|
| 43 |
+
```python
|
| 44 |
+
fig2 = px.line(df_stocks, x='date', y=['GOOG','AAPL'], labels={'x':'Date', 'y':'Price'},
|
| 45 |
+
title='Apple Vs. Google',template=selection_data.value)
|
| 46 |
+
```
|
| 47 |
+
"""
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
solara.FigurePlotly(fig2)
|
| 51 |
+
solara.SelectMultiple("Stocks", values= stocks, all_values= all_stocks, on_value =set_stocks)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Create a figure to which I'll add plots
|
| 55 |
+
fig3 = go.Figure()
|
| 56 |
+
# You can pull individual columns of data from the dataset and use markers or not
|
| 57 |
+
fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL,
|
| 58 |
+
mode='lines', name='Apple'))
|
| 59 |
+
fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN,
|
| 60 |
+
mode='lines+markers', name='Amazon'))
|
| 61 |
+
# You can create custom lines (Dashes : dash, dot, dashdot)
|
| 62 |
+
fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG,
|
| 63 |
+
mode='lines+markers', name='Google',
|
| 64 |
+
line=dict(color='firebrick', width=2, dash='dashdot')))
|
| 65 |
+
fig3.update_layout(template= selected_template.value)
|
| 66 |
+
|
| 67 |
+
solara.Markdown(f"###Create a figure to which I'll add plots")
|
| 68 |
+
|
| 69 |
+
solara.Markdown("""
|
| 70 |
+
```python
|
| 71 |
+
fig3 = go.Figure()
|
| 72 |
+
# You can pull individual columns of data from the dataset and use markers or not
|
| 73 |
+
fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL,
|
| 74 |
+
mode='lines', name='Apple'))
|
| 75 |
+
fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN,
|
| 76 |
+
mode='lines+markers', name='Amazon'))
|
| 77 |
+
# You can create custom lines (Dashes : dash, dot, dashdot)
|
| 78 |
+
fig3.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG,
|
| 79 |
+
mode='lines+markers', name='Google',
|
| 80 |
+
line=dict(color='firebrick', width=2, dash='dashdot')))
|
| 81 |
+
```
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
solara.FigurePlotly(fig3)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
solara.Markdown(f"###Go crazy styling the figure")
|
| 89 |
+
|
| 90 |
+
fig4 = go.Figure()
|
| 91 |
+
# You can pull individual columns of data from the dataset and use markers or not
|
| 92 |
+
fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL,
|
| 93 |
+
mode='lines', name='Apple'))
|
| 94 |
+
fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN,
|
| 95 |
+
mode='lines+markers', name='Amazon'))
|
| 96 |
+
# You can create custom lines (Dashes : dash, dot, dashdot)
|
| 97 |
+
fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG,
|
| 98 |
+
mode='lines+markers', name='Google',
|
| 99 |
+
line=dict(color='firebrick', width=2, dash='dashdot')))
|
| 100 |
+
fig4.update_layout(template= selected_template.value)
|
| 101 |
+
fig4.update_layout(
|
| 102 |
+
# Shows gray line without grid, styling fonts, linewidths and more
|
| 103 |
+
xaxis=dict(
|
| 104 |
+
showline=True,
|
| 105 |
+
showgrid=False,
|
| 106 |
+
showticklabels=True,
|
| 107 |
+
linecolor='rgb(204, 204, 204)',
|
| 108 |
+
linewidth=2,
|
| 109 |
+
ticks='outside',
|
| 110 |
+
tickfont=dict(
|
| 111 |
+
family='Arial',
|
| 112 |
+
size=12,
|
| 113 |
+
color='rgb(82, 82, 82)',
|
| 114 |
+
),
|
| 115 |
+
),
|
| 116 |
+
# Turn off everything on y axis
|
| 117 |
+
yaxis=dict(
|
| 118 |
+
showgrid=False,
|
| 119 |
+
zeroline=False,
|
| 120 |
+
showline=False,
|
| 121 |
+
showticklabels=False,
|
| 122 |
+
),
|
| 123 |
+
# autosize=False,
|
| 124 |
+
margin=dict(
|
| 125 |
+
autoexpand=False,
|
| 126 |
+
l=100,
|
| 127 |
+
r=20,
|
| 128 |
+
t=110,
|
| 129 |
+
),
|
| 130 |
+
showlegend=False,
|
| 131 |
+
plot_bgcolor='white'
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
solara.Markdown("""
|
| 135 |
+
```python
|
| 136 |
+
fig4 = go.Figure()
|
| 137 |
+
# You can pull individual columns of data from the dataset and use markers or not
|
| 138 |
+
fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AAPL,
|
| 139 |
+
mode='lines', name='Apple'))
|
| 140 |
+
fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.AMZN,
|
| 141 |
+
mode='lines+markers', name='Amazon'))
|
| 142 |
+
# You can create custom lines (Dashes : dash, dot, dashdot)
|
| 143 |
+
fig4.add_trace(go.Scatter(x=df_stocks.date, y=df_stocks.GOOG,
|
| 144 |
+
mode='lines+markers', name='Google',
|
| 145 |
+
line=dict(color='firebrick', width=2, dash='dashdot')))
|
| 146 |
+
fig4.update_layout(template= selection_data.value)
|
| 147 |
+
fig4.update_layout(
|
| 148 |
+
# Shows gray line without grid, styling fonts, linewidths and more
|
| 149 |
+
xaxis=dict(
|
| 150 |
+
showline=True,
|
| 151 |
+
showgrid=False,
|
| 152 |
+
showticklabels=True,
|
| 153 |
+
linecolor='rgb(204, 204, 204)',
|
| 154 |
+
linewidth=2,
|
| 155 |
+
ticks='outside',
|
| 156 |
+
tickfont=dict(
|
| 157 |
+
family='Arial',
|
| 158 |
+
size=12,
|
| 159 |
+
color='rgb(82, 82, 82)',
|
| 160 |
+
),
|
| 161 |
+
),
|
| 162 |
+
# Turn off everything on y axis
|
| 163 |
+
yaxis=dict(
|
| 164 |
+
showgrid=False,
|
| 165 |
+
zeroline=False,
|
| 166 |
+
showline=False,
|
| 167 |
+
showticklabels=False,
|
| 168 |
+
),
|
| 169 |
+
# autosize=False,
|
| 170 |
+
margin=dict(
|
| 171 |
+
autoexpand=False,
|
| 172 |
+
l=100,
|
| 173 |
+
r=20,
|
| 174 |
+
t=110,
|
| 175 |
+
),
|
| 176 |
+
showlegend=False,
|
| 177 |
+
plot_bgcolor='white'
|
| 178 |
+
)
|
| 179 |
+
```
|
| 180 |
+
"""
|
| 181 |
+
)
|
| 182 |
+
solara.FigurePlotly(fig4)
|
| 183 |
+
|
| 184 |
+
return main
|
pages/main.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
from utils import SharedSidebar
|
| 3 |
+
from bar import BarPlot
|
| 4 |
+
from line import LinePlot
|
| 5 |
+
from scatter import ScatterPlot
|
| 6 |
+
from pie import PieChart
|
| 7 |
+
from histogram import Histograms
|
| 8 |
+
from boxs import Boxs
|
| 9 |
+
from violin import Violins
|
| 10 |
+
from density_heatmap import DensityHeatmap
|
| 11 |
+
from treed_plot import TreeD
|
| 12 |
+
from maps import Maps
|
| 13 |
+
from other_plot import OtherPlots
|
| 14 |
+
from animated import AnimatedPlots
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@solara.component
|
| 18 |
+
def line():
|
| 19 |
+
with solara.Sidebar():
|
| 20 |
+
SharedSidebar()
|
| 21 |
+
LinePlot()
|
| 22 |
+
|
| 23 |
+
@solara.component
|
| 24 |
+
def bar():
|
| 25 |
+
with solara.Sidebar():
|
| 26 |
+
SharedSidebar()
|
| 27 |
+
BarPlot()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@solara.component
|
| 31 |
+
def scatter():
|
| 32 |
+
with solara.Sidebar():
|
| 33 |
+
SharedSidebar()
|
| 34 |
+
ScatterPlot()
|
| 35 |
+
|
| 36 |
+
@solara.component
|
| 37 |
+
def pie_chart():
|
| 38 |
+
with solara.Sidebar():
|
| 39 |
+
SharedSidebar()
|
| 40 |
+
PieChart()
|
| 41 |
+
|
| 42 |
+
@solara.component
|
| 43 |
+
def histogram():
|
| 44 |
+
with solara.Sidebar():
|
| 45 |
+
SharedSidebar()
|
| 46 |
+
Histograms()
|
| 47 |
+
|
| 48 |
+
@solara.component
|
| 49 |
+
def Box():
|
| 50 |
+
with solara.Sidebar():
|
| 51 |
+
SharedSidebar()
|
| 52 |
+
Boxs()
|
| 53 |
+
|
| 54 |
+
@solara.component
|
| 55 |
+
def violin():
|
| 56 |
+
with solara.Sidebar():
|
| 57 |
+
SharedSidebar()
|
| 58 |
+
Violins()
|
| 59 |
+
|
| 60 |
+
@solara.component
|
| 61 |
+
def density():
|
| 62 |
+
with solara.Sidebar():
|
| 63 |
+
SharedSidebar()
|
| 64 |
+
DensityHeatmap()
|
| 65 |
+
|
| 66 |
+
@solara.component
|
| 67 |
+
def treeD_plot():
|
| 68 |
+
with solara.Sidebar():
|
| 69 |
+
SharedSidebar()
|
| 70 |
+
TreeD()
|
| 71 |
+
|
| 72 |
+
@solara.component
|
| 73 |
+
def map():
|
| 74 |
+
with solara.Sidebar():
|
| 75 |
+
SharedSidebar()
|
| 76 |
+
Maps()
|
| 77 |
+
|
| 78 |
+
@solara.component
|
| 79 |
+
def other():
|
| 80 |
+
with solara.Sidebar():
|
| 81 |
+
SharedSidebar()
|
| 82 |
+
OtherPlots()
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
@solara.component
|
| 86 |
+
def animate():
|
| 87 |
+
with solara.Sidebar():
|
| 88 |
+
SharedSidebar()
|
| 89 |
+
AnimatedPlots()
|
| 90 |
+
|
| 91 |
+
routes = [
|
| 92 |
+
solara.Route(path="/", component=line, label="Line"),
|
| 93 |
+
solara.Route(path="bar", component=bar, label="Bar"),
|
| 94 |
+
solara.Route(path="scatter", component=scatter, label="Scatter"),
|
| 95 |
+
solara.Route(path="pie", component=pie_chart, label="Pie"),
|
| 96 |
+
solara.Route(path="histogram", component=histogram, label="Histogram"),
|
| 97 |
+
solara.Route(path="box", component=Box, label="Box"),
|
| 98 |
+
solara.Route(path="violin", component=violin, label="Violin"),
|
| 99 |
+
solara.Route(path="density-heatmap", component=density, label="Density-Heatmap"),
|
| 100 |
+
solara.Route(path="Plot_3D", component=treeD_plot, label="3D-Plot"),
|
| 101 |
+
solara.Route(path="map", component=map, label="Maps"),
|
| 102 |
+
solara.Route(path="other", component=other, label="Other_Plot"),
|
| 103 |
+
solara.Route(path="animated", component=animate, label="Animated_Plot"),
|
| 104 |
+
|
| 105 |
+
]
|
pages/maps.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
# You can color complex maps like we do here representing unemployment data
|
| 7 |
+
|
| 8 |
+
# Allows us to grab data from a supplied URL
|
| 9 |
+
from urllib.request import urlopen
|
| 10 |
+
# Used to decode JSON data
|
| 11 |
+
import json
|
| 12 |
+
# Grab US county geometry data
|
| 13 |
+
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
|
| 14 |
+
counties = json.load(response)
|
| 15 |
+
|
| 16 |
+
# Grab unemployment data based on each counties Federal Information Processing number
|
| 17 |
+
df2 = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
|
| 18 |
+
dtype={"fips": str})
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@solara.component
|
| 23 |
+
def Maps():
|
| 24 |
+
|
| 25 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 26 |
+
|
| 27 |
+
solara.Markdown(f"#Map Scatter Plots")
|
| 28 |
+
|
| 29 |
+
# There are many interesting ways of working with maps
|
| 30 |
+
# plotly.com/python-api-reference/generated/plotly.express.scatter_geo.html
|
| 31 |
+
df = px.data.gapminder().query("year == 2007")
|
| 32 |
+
fig1 = px.scatter_geo(df, locations="iso_alpha",
|
| 33 |
+
color="continent", # which column to use to set the color of markers
|
| 34 |
+
hover_name="country", # column added to hover information
|
| 35 |
+
size="pop", # size of markers
|
| 36 |
+
projection="orthographic",
|
| 37 |
+
template=selected_template.value
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# solara.Markdown(f"#### Use Box plot to compare different variables ")
|
| 42 |
+
solara.Markdown("""
|
| 43 |
+
```python
|
| 44 |
+
# There are many interesting ways of working with maps
|
| 45 |
+
# plotly.com/python-api-reference/generated/plotly.express.scatter_geo.html
|
| 46 |
+
df = px.data.gapminder().query("year == 2007")
|
| 47 |
+
fig = px.scatter_geo(df, locations="iso_alpha",
|
| 48 |
+
color="continent", # which column to use to set the color of markers
|
| 49 |
+
hover_name="country", # column added to hover information
|
| 50 |
+
size="pop", # size of markers
|
| 51 |
+
projection="orthographic")
|
| 52 |
+
```
|
| 53 |
+
"""
|
| 54 |
+
)
|
| 55 |
+
solara.FigurePlotly(fig1)
|
| 56 |
+
|
| 57 |
+
# Draw map using the county JSON data, color using unemployment values on a range of 12
|
| 58 |
+
fig2 = px.choropleth(df2, geojson=counties, locations='fips', color='unemp',
|
| 59 |
+
color_continuous_scale="Viridis",
|
| 60 |
+
range_color=(0, 12),
|
| 61 |
+
scope="usa",
|
| 62 |
+
labels={'unemp':'unemployment rate'},
|
| 63 |
+
template=selected_template.value
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
solara.Markdown(f"####Choropleth Maps")
|
| 67 |
+
solara.Markdown("""
|
| 68 |
+
```python
|
| 69 |
+
# You can color complex maps like we do here representing unemployment data
|
| 70 |
+
|
| 71 |
+
# Allows us to grab data from a supplied URL
|
| 72 |
+
from urllib.request import urlopen
|
| 73 |
+
# Used to decode JSON data
|
| 74 |
+
import json
|
| 75 |
+
# Grab US county geometry data
|
| 76 |
+
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
|
| 77 |
+
counties = json.load(response)
|
| 78 |
+
|
| 79 |
+
# Grab unemployment data based on each counties Federal Information Processing number
|
| 80 |
+
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
|
| 81 |
+
dtype={"fips": str})
|
| 82 |
+
|
| 83 |
+
# Draw map using the county JSON data, color using unemployment values on a range of 12
|
| 84 |
+
fig2 = px.choropleth(df, geojson=counties, locations='fips', color='unemp',
|
| 85 |
+
color_continuous_scale="Viridis",
|
| 86 |
+
range_color=(0, 12),
|
| 87 |
+
scope="usa",
|
| 88 |
+
labels={'unemp':'unemployment rate'}
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
```
|
| 92 |
+
"""
|
| 93 |
+
)
|
| 94 |
+
solara.FigurePlotly(fig2)
|
| 95 |
+
|
| 96 |
+
return main
|
pages/other_plot.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import seaborn as sns
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@solara.component
|
| 8 |
+
def OtherPlots():
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 12 |
+
|
| 13 |
+
solara.Markdown(f"#Polar Chart")
|
| 14 |
+
|
| 15 |
+
# Polar charts display data radially
|
| 16 |
+
# Let's plot wind data based on direction and frequency
|
| 17 |
+
# You can change size and auto-generate different symbols as well
|
| 18 |
+
df_wind = px.data.wind()
|
| 19 |
+
px.scatter_polar(df_wind, r="frequency", theta="direction", color="strength",
|
| 20 |
+
size="frequency", symbol="strength",
|
| 21 |
+
template=selected_template.value)
|
| 22 |
+
|
| 23 |
+
# Data can also be plotted using lines radially
|
| 24 |
+
# A template makes the data easier to see
|
| 25 |
+
fig1 = px.line_polar(df_wind, r="frequency", theta="direction", color="strength",
|
| 26 |
+
line_close=True, template="plotly_dark", width=800, height=400)
|
| 27 |
+
|
| 28 |
+
solara.Markdown("""
|
| 29 |
+
```python
|
| 30 |
+
# Polar charts display data radially
|
| 31 |
+
# Let's plot wind data based on direction and frequency
|
| 32 |
+
# You can change size and auto-generate different symbols as well
|
| 33 |
+
df_wind = px.data.wind()
|
| 34 |
+
px.scatter_polar(df_wind, r="frequency", theta="direction", color="strength",
|
| 35 |
+
size="frequency", symbol="strength")
|
| 36 |
+
|
| 37 |
+
# Data can also be plotted using lines radially
|
| 38 |
+
# A template makes the data easier to see
|
| 39 |
+
fig1 = px.line_polar(df_wind, r="frequency", theta="direction", color="strength",
|
| 40 |
+
line_close=True, template="plotly_dark", width=800, height=400)
|
| 41 |
+
```
|
| 42 |
+
"""
|
| 43 |
+
)
|
| 44 |
+
solara.FigurePlotly(fig1)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# Used to represent ratios of 3 variables
|
| 48 |
+
df_exp = px.data.experiment()
|
| 49 |
+
fig2 = px.scatter_ternary(df_exp, a="experiment_1", b="experiment_2",
|
| 50 |
+
c='experiment_3', hover_name="group", color="gender",template=selected_template.value)
|
| 51 |
+
|
| 52 |
+
solara.Markdown(f"#Ternary Plot")
|
| 53 |
+
solara.Markdown("""
|
| 54 |
+
```python
|
| 55 |
+
# Used to represent ratios of 3 variables
|
| 56 |
+
df_exp = px.data.experiment()
|
| 57 |
+
px.scatter_ternary(df_exp, a="experiment_1", b="experiment_2",
|
| 58 |
+
c='experiment_3', hover_name="group", color="gender")
|
| 59 |
+
```
|
| 60 |
+
"""
|
| 61 |
+
)
|
| 62 |
+
solara.FigurePlotly(fig2)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# You can create numerous subplots
|
| 67 |
+
df_tips = px.data.tips()
|
| 68 |
+
fig3= px.scatter(df_tips, x="total_bill", y="tip", color="smoker", facet_col="sex",
|
| 69 |
+
template=selected_template.value)
|
| 70 |
+
|
| 71 |
+
# We can line up data in rows and columns
|
| 72 |
+
fig4 = px.histogram(df_tips, x="total_bill", y="tip", color="sex", facet_row="time", facet_col="day",template=selected_template.value,
|
| 73 |
+
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
|
| 74 |
+
|
| 75 |
+
# This dataframe provides scores for different students based on the level
|
| 76 |
+
# of attention they could provide during testing
|
| 77 |
+
att_df = sns.load_dataset("attention")
|
| 78 |
+
fig5 = px.line(att_df, x='solutions', y='score', facet_col='subject',
|
| 79 |
+
facet_col_wrap=5, title='Scores Based on Attention',
|
| 80 |
+
template=selected_template.value)
|
| 81 |
+
|
| 82 |
+
solara.Markdown(f"#Facets")
|
| 83 |
+
solara.Markdown("""
|
| 84 |
+
```python
|
| 85 |
+
# You can create numerous subplots
|
| 86 |
+
df_tips = px.data.tips()
|
| 87 |
+
px.scatter(df_tips, x="total_bill", y="tip", color="smoker", facet_col="sex")
|
| 88 |
+
|
| 89 |
+
# We can line up data in rows and columns
|
| 90 |
+
fig3 = px.histogram(df_tips, x="total_bill", y="tip", color="sex", facet_row="time", facet_col="day",
|
| 91 |
+
category_orders={"day": ["Thur", "Fri", "Sat", "Sun"], "time": ["Lunch", "Dinner"]})
|
| 92 |
+
|
| 93 |
+
# This dataframe provides scores for different students based on the level
|
| 94 |
+
# of attention they could provide during testing
|
| 95 |
+
att_df = sns.load_dataset("attention")
|
| 96 |
+
fig4 = fig = px.line(att_df, x='solutions', y='score', facet_col='subject',
|
| 97 |
+
facet_col_wrap=5, title='Scores Based on Attention')
|
| 98 |
+
```
|
| 99 |
+
"""
|
| 100 |
+
)
|
| 101 |
+
solara.FigurePlotly(fig3)
|
| 102 |
+
solara.FigurePlotly(fig4)
|
| 103 |
+
solara.FigurePlotly(fig5)
|
| 104 |
+
|
| 105 |
+
return main
|
pages/pie.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
@solara.component
|
| 7 |
+
def PieChart():
|
| 8 |
+
|
| 9 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 10 |
+
|
| 11 |
+
solara.Markdown(f"#PIE CHARTS")
|
| 12 |
+
# Use included Iris data set
|
| 13 |
+
df_samer = px.data.gapminder().query("year == 2007").query("continent == 'Asia'")
|
| 14 |
+
|
| 15 |
+
fig1= px.pie(df_samer, values='pop', names='country', height= 700,
|
| 16 |
+
title='Population of Asian continent',template= selected_template.value,
|
| 17 |
+
color_discrete_sequence=px.colors.sequential.RdBu)
|
| 18 |
+
|
| 19 |
+
solara.Markdown(f"#### Create Pie chart of the largest nations in Asia ")
|
| 20 |
+
solara.Markdown("[Color maps here](https://plotly.com/python/builtin-colorscales)")
|
| 21 |
+
solara.Markdown("""
|
| 22 |
+
```python
|
| 23 |
+
# Use included Iris data set
|
| 24 |
+
df_samer = px.data.gapminder().query("year == 2007").query("continent == 'Asia'")
|
| 25 |
+
fig1= px.pie(df_samer, values='pop', names='country',
|
| 26 |
+
title='Population of Asian continent',
|
| 27 |
+
color_discrete_sequence=px.colors.sequential.RdBu)
|
| 28 |
+
```
|
| 29 |
+
"""
|
| 30 |
+
)
|
| 31 |
+
solara.FigurePlotly(fig1)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Customize pie chart
|
| 36 |
+
colors = ['blue', 'green', 'black', 'purple', 'red', 'brown']
|
| 37 |
+
fig2 = go.Figure(data=[go.Pie(labels=['Water','Grass','Normal','Psychic', 'Fire', 'Ground'],
|
| 38 |
+
values=[110,90,80,80,70,60])])
|
| 39 |
+
# Define hover info, text size, pull amount for each pie slice, and stroke
|
| 40 |
+
fig2.update_traces(hoverinfo='label+percent', textfont_size=15,
|
| 41 |
+
textinfo='label+percent', pull=[0.1, 0, 0.2, 0, 0, 0],
|
| 42 |
+
marker=dict(colors=colors, line=dict(color='yellow', width=2)))
|
| 43 |
+
fig2.update_layout(template= selected_template.value)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
solara.Markdown(f"#### Customize pie chart")
|
| 47 |
+
solara.Markdown("""
|
| 48 |
+
```python
|
| 49 |
+
# Customize pie chart
|
| 50 |
+
colors = ['blue', 'green', 'black', 'purple', 'red', 'brown']
|
| 51 |
+
fig2 = go.Figure(data=[go.Pie(labels=['Water','Grass','Normal','Psychic', 'Fire', 'Ground'],
|
| 52 |
+
values=[110,90,80,80,70,60])])
|
| 53 |
+
# Define hover info, text size, pull amount for each pie slice, and stroke
|
| 54 |
+
fig2.update_traces(hoverinfo='label+percent', textfont_size=15,
|
| 55 |
+
textinfo='label+percent', pull=[0.1, 0, 0.2, 0, 0, 0],
|
| 56 |
+
marker=dict(colors=colors, line=dict(color='yellow', width=2)))
|
| 57 |
+
```
|
| 58 |
+
"""
|
| 59 |
+
)
|
| 60 |
+
solara.FigurePlotly(fig2)
|
| 61 |
+
return main
|
pages/scatter.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import numpy as np
|
| 3 |
+
import seaborn as sns
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
import plotly.graph_objects as go
|
| 6 |
+
from utils import selected_template
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@solara.component
|
| 10 |
+
def ScatterPlot():
|
| 11 |
+
with solara.Row(justify='space-around') as main:
|
| 12 |
+
with solara.Column(gap="10px",align="stretch"):
|
| 13 |
+
with solara.Card():
|
| 14 |
+
with solara.Row():
|
| 15 |
+
with solara.Column():
|
| 16 |
+
selection_data, set_selection_data = solara.use_state(None)
|
| 17 |
+
click_data, set_click_data = solara.use_state(None)
|
| 18 |
+
hover_data, set_hover_data = solara.use_state(None)
|
| 19 |
+
unhover_data, set_unhover_data = solara.use_state(None)
|
| 20 |
+
deselect_data, set_deselect_data = solara.use_state(None)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
solara.Markdown(f"#SCATTER PLOTS")
|
| 24 |
+
# Use included Iris data set
|
| 25 |
+
df_iris = px.data.iris()
|
| 26 |
+
# Create a scatter plot by defining x, y, different color for count of provided
|
| 27 |
+
# column, size based on supplied column and additional data to display on hover
|
| 28 |
+
fig1= px.scatter(df_iris, x="sepal_width", y="sepal_length", color="species", template=selected_template.value,
|
| 29 |
+
size='petal_length', hover_data=['petal_width'])
|
| 30 |
+
|
| 31 |
+
solara.Markdown(f"###Create a scatter plot by defining x, y, different color for count of provided")
|
| 32 |
+
solara.Markdown("""
|
| 33 |
+
```python
|
| 34 |
+
fig1= px.scatter(df_iris, x="sepal_width", y="sepal_length", color="species",
|
| 35 |
+
size='petal_length', hover_data=['petal_width'])
|
| 36 |
+
```
|
| 37 |
+
"""
|
| 38 |
+
)
|
| 39 |
+
solara.FigurePlotly(fig1, on_selection=set_selection_data,
|
| 40 |
+
on_click=set_click_data, on_hover=set_hover_data,
|
| 41 |
+
on_unhover=set_unhover_data, on_deselect=set_deselect_data)
|
| 42 |
+
|
| 43 |
+
with solara.Columns():
|
| 44 |
+
solara.Markdown(
|
| 45 |
+
f"""
|
| 46 |
+
# Events data
|
| 47 |
+
## selection
|
| 48 |
+
```
|
| 49 |
+
{selection_data}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
## click
|
| 53 |
+
```
|
| 54 |
+
{click_data}
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
## hover
|
| 58 |
+
```
|
| 59 |
+
{hover_data}
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## unhover
|
| 63 |
+
```
|
| 64 |
+
{unhover_data}
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
## deselect
|
| 68 |
+
```
|
| 69 |
+
{deselect_data}
|
| 70 |
+
```
|
| 71 |
+
"""
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
with solara.Column(gap="10px",align="stretch"):
|
| 75 |
+
# Create a customized scatter with black marker edges with line width 2, opaque
|
| 76 |
+
# and colored based on width. Also show a scale on the right
|
| 77 |
+
fig2 = go.Figure()
|
| 78 |
+
fig2.add_trace(go.Scatter(
|
| 79 |
+
x=df_iris.sepal_width, y=df_iris.sepal_length,
|
| 80 |
+
mode='markers',
|
| 81 |
+
marker_color=df_iris.sepal_width,
|
| 82 |
+
text=df_iris.species,
|
| 83 |
+
marker=dict(showscale=True)
|
| 84 |
+
))
|
| 85 |
+
fig2.update_traces(marker_line_width=2, marker_size=10)
|
| 86 |
+
fig2.update_layout(template= selected_template.value)
|
| 87 |
+
solara.Markdown(f"##Create a customized scatter with black marker edges with line width 2, opaque and colored based on width. Also show a scale on the right")
|
| 88 |
+
solara.Markdown("""
|
| 89 |
+
```python
|
| 90 |
+
fig2 = go.Figure()
|
| 91 |
+
fig2.add_trace(go.Scatter(
|
| 92 |
+
x=df_iris.sepal_width, y=df_iris.sepal_length,
|
| 93 |
+
mode='markers',
|
| 94 |
+
marker_color=df_iris.sepal_width,
|
| 95 |
+
text=df_iris.species,
|
| 96 |
+
marker=dict(showscale=True)
|
| 97 |
+
))
|
| 98 |
+
fig2.update_traces(marker_line_width=2, marker_size=10)
|
| 99 |
+
```
|
| 100 |
+
"""
|
| 101 |
+
)
|
| 102 |
+
solara.FigurePlotly(fig2)
|
| 103 |
+
|
| 104 |
+
# Working with a lot of data use Scattergl
|
| 105 |
+
fig3 = go.Figure(data=go.Scattergl(
|
| 106 |
+
x = np.random.randn(10000),
|
| 107 |
+
y = np.random.randn(10000),
|
| 108 |
+
mode='markers',
|
| 109 |
+
marker=dict(
|
| 110 |
+
color=np.random.randn(10000),
|
| 111 |
+
colorscale='Viridis',
|
| 112 |
+
line_width=1
|
| 113 |
+
)
|
| 114 |
+
))
|
| 115 |
+
fig3.update_layout(template= selected_template.value)
|
| 116 |
+
|
| 117 |
+
solara.Markdown(f"#Working with a lot of data use *Scattergl*")
|
| 118 |
+
solara.Markdown("""
|
| 119 |
+
```python
|
| 120 |
+
fig3 = go.Figure(data=go.Scattergl(
|
| 121 |
+
x = np.random.randn(10000),
|
| 122 |
+
y = np.random.randn(10000),
|
| 123 |
+
mode='markers',
|
| 124 |
+
marker=dict(
|
| 125 |
+
color=np.random.randn(10000),
|
| 126 |
+
colorscale='Viridis',
|
| 127 |
+
line_width=1
|
| 128 |
+
)
|
| 129 |
+
))
|
| 130 |
+
```
|
| 131 |
+
"""
|
| 132 |
+
)
|
| 133 |
+
solara.FigurePlotly(fig3)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
# With a scatter matrix we can compare changes when comparing column data
|
| 139 |
+
flights = sns.load_dataset("flights")
|
| 140 |
+
|
| 141 |
+
fig4 = px.scatter_matrix(flights, color='month',template=selected_template.value,)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
solara.Markdown(f"##Scatter Matrix")
|
| 145 |
+
solara.Markdown("""
|
| 146 |
+
```python
|
| 147 |
+
# With a scatter matrix we can compare changes when comparing column data
|
| 148 |
+
flights = sns.load_dataset("flights")
|
| 149 |
+
fig3 = px.scatter_matrix(flights, color='month')
|
| 150 |
+
```
|
| 151 |
+
"""
|
| 152 |
+
)
|
| 153 |
+
solara.FigurePlotly(fig4)
|
| 154 |
+
|
| 155 |
+
return main
|
pages/treed_plot.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import seaborn as sns
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
@solara.component
|
| 7 |
+
def TreeD():
|
| 8 |
+
|
| 9 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 10 |
+
|
| 11 |
+
solara.Markdown(f"#3D Scatter Plots")
|
| 12 |
+
|
| 13 |
+
flights = sns.load_dataset("flights")
|
| 14 |
+
# Create a 3D scatter plot using flight data
|
| 15 |
+
fig1 = px.scatter_3d(flights, x='year', y='month', z='passengers', color='year',
|
| 16 |
+
opacity=0.7,
|
| 17 |
+
width=800, height=400,
|
| 18 |
+
template=selected_template.value)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# solara.Markdown(f"#### Use Box plot to compare different variables ")
|
| 22 |
+
solara.Markdown("""
|
| 23 |
+
```python
|
| 24 |
+
flights = sns.load_dataset("flights")
|
| 25 |
+
# Create a 3D scatter plot using flight data
|
| 26 |
+
fig1 = px.scatter_3d(flights, x='year', y='month', z='passengers', color='year',
|
| 27 |
+
opacity=0.7, width=800, height=400)
|
| 28 |
+
```
|
| 29 |
+
"""
|
| 30 |
+
)
|
| 31 |
+
solara.FigurePlotly(fig1)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# With a scatter matrix we can compare changes when comparing column data
|
| 35 |
+
fig2 = px.line_3d(flights, x='year', y='month', z='passengers', color='year',template=selected_template.value)
|
| 36 |
+
|
| 37 |
+
solara.Markdown(f"#3D Line Plots")
|
| 38 |
+
solara.Markdown("""
|
| 39 |
+
```python
|
| 40 |
+
# With a scatter matrix we can compare changes when comparing column data
|
| 41 |
+
fig2 = px.line_3d(flights, x='year', y='month', z='passengers', color='year')
|
| 42 |
+
|
| 43 |
+
```
|
| 44 |
+
"""
|
| 45 |
+
)
|
| 46 |
+
solara.FigurePlotly(fig2)
|
| 47 |
+
|
| 48 |
+
return main
|
pages/utils.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
|
| 3 |
+
selected_template = solara.reactive("plotly")
|
| 4 |
+
def change_theme(e):
|
| 5 |
+
print (selected_template.value)
|
| 6 |
+
templates =["plotly", "plotly_white", "plotly_dark", "ggplot2", "seaborn", "simple_white", "none"]
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@solara.component
|
| 10 |
+
def SharedSidebar():
|
| 11 |
+
with solara.Card("Solara + Plotly Graphs", style={"max-width": "500px"}):
|
| 12 |
+
solara.Markdown(
|
| 13 |
+
f"""
|
| 14 |
+
###This project utilizes the Solara Framework to create interactive graphs using Plotly.
|
| 15 |
+
*The code and examples in this project are based on the Plotly tutorial by Derek Banas.*
|
| 16 |
+
*Please refer to his repository for the original tutorial [here](https://github.com/derekbanas/plotly-tutorial/blob/master/Plotly%20Tut.ipynb)*
|
| 17 |
+
"""
|
| 18 |
+
)
|
| 19 |
+
with solara.Card(style={"max-width": "500px"}):
|
| 20 |
+
solara.Select(label="Themes", value=selected_template, values=templates, on_value=change_theme)
|
pages/violin.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import solara
|
| 2 |
+
import plotly.express as px
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
from utils import selected_template
|
| 5 |
+
|
| 6 |
+
@solara.component
|
| 7 |
+
def Violins():
|
| 8 |
+
|
| 9 |
+
with solara.Column(gap="20px", align = "stretch") as main:
|
| 10 |
+
|
| 11 |
+
solara.Markdown(f"#VIOLIN PLOTS")
|
| 12 |
+
|
| 13 |
+
# Violin Plot is a combination of the boxplot and KDE
|
| 14 |
+
# While a box plot corresponds to data points, the violin plot uses the KDE estimation
|
| 15 |
+
# of the data points
|
| 16 |
+
df_tips = px.data.tips()
|
| 17 |
+
fig1= px.violin(df_tips, y="total_bill", box=True, points='all',template=selected_template.value)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# solara.Markdown(f"#### Use Box plot to compare different variables ")
|
| 21 |
+
solara.Markdown("""
|
| 22 |
+
```python
|
| 23 |
+
# Violin Plot is a combination of the boxplot and KDE
|
| 24 |
+
# While a box plot corresponds to data points, the violin plot uses the KDE estimation
|
| 25 |
+
# of the data points
|
| 26 |
+
df_tips = px.data.tips()
|
| 27 |
+
px.violin(df_tips, y="total_bill", box=True, points='all')
|
| 28 |
+
```
|
| 29 |
+
"""
|
| 30 |
+
)
|
| 31 |
+
solara.FigurePlotly(fig1)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# Multiple plots
|
| 35 |
+
fig2 = px.violin(df_tips, y="tip", x="smoker", color="sex", box=True, points="all",
|
| 36 |
+
hover_data=df_tips.columns,template=selected_template.value)
|
| 37 |
+
|
| 38 |
+
solara.Markdown(f"####Multiple plots")
|
| 39 |
+
solara.Markdown("""
|
| 40 |
+
```python
|
| 41 |
+
# Multiple plots
|
| 42 |
+
px.violin(df_tips, y="tip", x="smoker", color="sex", box=True, points="all",
|
| 43 |
+
hover_data=df_tips.columns)
|
| 44 |
+
```
|
| 45 |
+
"""
|
| 46 |
+
)
|
| 47 |
+
solara.FigurePlotly(fig2)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# Morph left and right sides based on if the customer smokes
|
| 52 |
+
fig3 = go.Figure()
|
| 53 |
+
fig3.add_trace(go.Violin(x=df_tips['day'][ df_tips['smoker'] == 'Yes' ],
|
| 54 |
+
y=df_tips['total_bill'][ df_tips['smoker'] == 'Yes' ],
|
| 55 |
+
legendgroup='Yes', scalegroup='Yes', name='Yes',
|
| 56 |
+
side='negative',
|
| 57 |
+
line_color='blue'))
|
| 58 |
+
fig3.add_trace(go.Violin(x=df_tips['day'][ df_tips['smoker'] == 'No' ],
|
| 59 |
+
y=df_tips['total_bill'][ df_tips['smoker'] == 'No' ],
|
| 60 |
+
legendgroup='Yes', scalegroup='Yes', name='No',
|
| 61 |
+
side='positive',
|
| 62 |
+
line_color='red'))
|
| 63 |
+
fig3.update_layout(template= selected_template.value)
|
| 64 |
+
|
| 65 |
+
solara.Markdown(f"####MMorph left and right sides based on if the customer smokes")
|
| 66 |
+
solara.Markdown("""
|
| 67 |
+
```python
|
| 68 |
+
# Morph left and right sides based on if the customer smokes
|
| 69 |
+
fig3 = go.Figure()
|
| 70 |
+
fig3.add_trace(go.Violin(x=df_tips['day'][ df_tips['smoker'] == 'Yes' ],
|
| 71 |
+
y=df_tips['total_bill'][ df_tips['smoker'] == 'Yes' ],
|
| 72 |
+
legendgroup='Yes', scalegroup='Yes', name='Yes',
|
| 73 |
+
side='negative',
|
| 74 |
+
line_color='blue'))
|
| 75 |
+
fig3.add_trace(go.Violin(x=df_tips['day'][ df_tips['smoker'] == 'No' ],
|
| 76 |
+
y=df_tips['total_bill'][ df_tips['smoker'] == 'No' ],
|
| 77 |
+
legendgroup='Yes', scalegroup='Yes', name='No',
|
| 78 |
+
side='positive',
|
| 79 |
+
line_color='red'))
|
| 80 |
+
```
|
| 81 |
+
"""
|
| 82 |
+
)
|
| 83 |
+
solara.FigurePlotly(fig3)
|
| 84 |
+
return main
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
solara
|
| 2 |
pandas
|
| 3 |
-
|
|
|
|
|
|
| 1 |
solara
|
| 2 |
pandas
|
| 3 |
+
plotly
|
| 4 |
+
seaborn
|