Skip to content

Commit

Permalink
clean up a bit on the layout
Browse files Browse the repository at this point in the history
  • Loading branch information
unkcpz committed Jul 7, 2024
1 parent 1cf469b commit ec680c3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 86 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ classifiers = [
dependencies = [
"aiida-sssp-workflow",
"solara",
"vaex",
"anywidget>=0.9.0",
"humanfriendly",
]
Expand Down
34 changes: 1 addition & 33 deletions src/aiidalab_sssp/data.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
import dataclasses
from pathlib import Path
from typing import Any, Dict
from typing import Dict

import vaex.datasets
import yaml


@dataclasses.dataclass
class DataFrame:
title: str
df: Any
image_url: str


dfs = {
"titanic": DataFrame(
df=vaex.datasets.titanic(),
title="Titanic",
image_url="https://images.unsplash.com/photo-1561625116-df74735458a5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3574&q=80", # noqa
),
"iris": DataFrame(
df=vaex.datasets.iris(),
title="Iris",
image_url="https://images.unsplash.com/photo-1540163502599-a3284e17072d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3870&q=80", # noqa
),
# uncomment for a larger dataset to be included
# "taxi": DataFrame(
# df=vaex.datasets.taxi(),
# title="New York Taxi",
# image_url="https://images.unsplash.com/photo-1514749204155-24e484635226?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1587&q=80", # noqa
# ),
}

names = list(dfs)
# def load(name):
# if name == "titanic"

HERE = Path(__file__)


Expand Down
11 changes: 3 additions & 8 deletions src/aiidalab_sssp/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import solara
from solara.alias import rv

from aiidalab_sssp.pages import explore
from aiidalab_sssp.data import articles, names
from aiidalab_sssp.pages import explore, verify
from aiidalab_sssp.data import articles
from aiidalab_sssp.components import banner


Expand Down Expand Up @@ -30,11 +30,6 @@ def Layout(children=[]):
with solara.Link(solara.resolve_path("/")):
with solara.ListItem("Home", icon_name="mdi-home", value="/"):
pass
with solara.ListItem("tabular data", icon_name="mdi-database"):
for name in names:
pathname = f"/tabular/{name}"
with solara.Link(solara.resolve_path(pathname)):
solara.ListItem(name, value=pathname)
with solara.ListItem("Articles", icon_name="mdi-book-open"):
for name, article_ in articles.items():
pathname = f"/article/{name}"
Expand All @@ -52,7 +47,7 @@ def Page():
solara.Title("Standard Solid-State Pseudopotential (SSSP) » Home")
with solara.ColumnsResponsive(12):
banner.Overview()
with solara.ColumnsResponsive([6, 6]):
with solara.ColumnsResponsive([6, 6], small=[12]):
explore.Overview()
verify.Overview()

Expand Down
88 changes: 44 additions & 44 deletions src/aiidalab_sssp/pages/explore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,50 @@ def Page(type: Optional[str] = None, name: Optional[str] = None, x: Optional[str
with solara.ColumnsResponsive(12):
viz.PerioicTable()

if type is None:
type = "scatter"
set_type("scatter")
with solara.Sidebar():
with solara.Card("Viz configuration"):
solara.Select(label="dataset", value=name, values=list(data.dfs), on_value=set_name)
solara.ToggleButtonsSingle(value=type, values=["scatter", "histogram"], on_value=set_type)
if name not in data.dfs:
set_name(list(data.dfs)[0])
if name in data.dfs:
df = data.dfs[name].df
column_names = df.get_column_names()
df = df.to_pandas_df()
if x not in column_names:
set_x(column_names[0])
if y not in column_names:
set_y(column_names[1])
if x not in column_names:
set_x(column_names[0])
if y not in column_names:
set_y(column_names[1])
solara.Title(f"Solara demo » viz » {type} » {name}")
fig = None
if type == "scatter":
with solara.Sidebar():
with solara.Card("Columns"):
solara.Select(label="x", value=x, values=column_names, on_value=set_x)
solara.Select(label="y", value=y, values=column_names, on_value=set_y)
if x and y and x in column_names and y in column_names:
fig = px.scatter(df, x=x, y=y)
else:
solara.Warning("Please provide x and y")
elif type == "histogram":
with solara.Sidebar():
with solara.Card("Columns"):
solara.Select(label="x", value=x, values=column_names, on_value=set_x)
if x and x in column_names:
fig = px.histogram(df, x=x)
else:
solara.Warning("Please provide x")
else:
solara.Error("Uknonwn ")
if fig:
solara.FigurePlotly(fig, dependencies=[name, type, x, y])
# if type is None:
# type = "scatter"
# set_type("scatter")
# with solara.Sidebar():
# with solara.Card("Viz configuration"):
# solara.Select(label="dataset", value=name, values=list(data.dfs), on_value=set_name)
# solara.ToggleButtonsSingle(value=type, values=["scatter", "histogram"], on_value=set_type)
# if name not in data.dfs:
# set_name(list(data.dfs)[0])
# if name in data.dfs:
# df = data.dfs[name].df
# column_names = df.get_column_names()
# df = df.to_pandas_df()
# if x not in column_names:
# set_x(column_names[0])
# if y not in column_names:
# set_y(column_names[1])
# if x not in column_names:
# set_x(column_names[0])
# if y not in column_names:
# set_y(column_names[1])
# solara.Title(f"Solara demo » viz » {type} » {name}")
# fig = None
# if type == "scatter":
# with solara.Sidebar():
# with solara.Card("Columns"):
# solara.Select(label="x", value=x, values=column_names, on_value=set_x)
# solara.Select(label="y", value=y, values=column_names, on_value=set_y)
# if x and y and x in column_names and y in column_names:
# fig = px.scatter(df, x=x, y=y)
# else:
# solara.Warning("Please provide x and y")
# elif type == "histogram":
# with solara.Sidebar():
# with solara.Card("Columns"):
# solara.Select(label="x", value=x, values=column_names, on_value=set_x)
# if x and x in column_names:
# fig = px.histogram(df, x=x)
# else:
# solara.Warning("Please provide x")
# else:
# solara.Error("Uknonwn ")
# if fig:
# solara.FigurePlotly(fig, dependencies=[name, type, x, y])
return main

@solara.component
Expand Down

0 comments on commit ec680c3

Please sign in to comment.