Skip to content

Commit 3f4e2c1

Browse files
authored
Merge pull request #52 from ComputationalPhysiology/fix-gui
Update gui for new version of streamlit and favor gotranx over gotran¨
2 parents 9f18de3 + 9b372a3 commit 3f4e2c1

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

src/modelgraph/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
if __name__ == "__main__":
22
from .cli import main
33

4-
main()
4+
raise SystemExit(main())

src/modelgraph/cli.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,26 @@
2424
def main(filename):
2525
os.environ["MODELGRAPH_FILENAME"] = filename
2626
# Make sure we can import the required packages
27-
from . import gui # noqa: F401
2827
from pathlib import Path
28+
import sys
29+
import subprocess as sp
30+
31+
try:
32+
import streamlit # noqa: F401
33+
except ImportError:
34+
print("Please install streamlit - python3 -m pip install streamlit")
35+
exit(1)
36+
37+
try:
38+
import gotranx # noqa: F401
39+
except ImportError:
40+
try:
41+
import gotran # noqa: F401
42+
except ImportError:
43+
print("Please install gotranx or gotran - python3 -m pip install gotranx")
44+
exit(1)
2945

3046
gui_path = Path(__file__).parent.joinpath("gui.py")
31-
import subprocess as sp
47+
args = [sys.executable, "-m", "streamlit", "run", gui_path.as_posix()]
3248

33-
sp.run(["streamlit", "run", gui_path.as_posix()])
49+
sp.run(args)

src/modelgraph/gui.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
print("Please install streamlit - python3 -m pip install streamlit")
1212
exit(1)
1313

14-
15-
import gotran
14+
try:
15+
import gotranx as gotran
16+
except ImportError:
17+
import gotran
1618

1719
from modelgraph import DependencyGraph
1820

1921

2022
here = Path(__file__).absolute().parent
2123

2224

23-
@st.cache(allow_output_mutation=True)
25+
@st.cache_data
2426
def get_graph():
2527
ode = gotran.load_ode(os.getenv("MODELGRAPH_FILENAME"))
2628
return DependencyGraph(ode)
@@ -52,26 +54,28 @@ def inv_dependency_graph():
5254
st.image(temp.name)
5355

5456

55-
# Page settings
56-
st.set_page_config(page_title="modelgraph")
57+
if __name__ == "__main__":
58+
# Page settings
59+
st.set_page_config(page_title="modelgraph")
5760

58-
# Sidebar settings
59-
pages = {
60-
"Dendencency graph": dependency_graph,
61-
"Inverse dendencency graph": inv_dependency_graph,
62-
}
61+
# Sidebar settings
62+
pages = {
63+
"Dendencency graph": dependency_graph,
64+
"Inverse dendencency graph": inv_dependency_graph,
65+
}
6366

64-
st.sidebar.title("modelgraph")
67+
st.sidebar.title("modelgraph")
6568

66-
# Radio buttons to select desired option
67-
page = st.sidebar.radio("", tuple(pages.keys()))
69+
# Radio buttons to select desired option
70+
keys = list(pages.keys())
71+
page = st.sidebar.radio("Select a page", keys)
6872

69-
pages[page]()
73+
pages[page]()
7074

71-
# About
72-
st.sidebar.markdown(
73-
"""
74-
- [Source code](https://github.com/ComputationalPhysiology/modelgraph)
75-
- [Documentation](https://computationalphysiology.github.io/modelgraph/)
76-
""",
77-
)
75+
# About
76+
st.sidebar.markdown(
77+
"""
78+
- [Source code](https://github.com/ComputationalPhysiology/modelgraph)
79+
- [Documentation](https://computationalphysiology.github.io/modelgraph/)
80+
""",
81+
)

0 commit comments

Comments
 (0)