-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.py
91 lines (80 loc) · 2.29 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import inspect
import textwrap
from collections import OrderedDict
import streamlit as st
from streamlit.logger import get_logger
from streamlit.hello import demos
LOGGER = get_logger(__name__)
# Dictionary of
# demo_name -> (demo_function, demo_description)
DEMOS = OrderedDict(
[
("—", (demos.intro, None)),
(
"Animation Demo",
(
demos.fractal_demo,
"""
This app shows how you can use Streamlit to build cool animations.
It displays an animated fractal based on the the Julia Set. Use the slider
to tune different parameters.
""",
),
),
(
"Plotting Demo",
(
demos.plotting_demo,
"""
This demo illustrates a combination of plotting and animation with
Streamlit. We're generating a bunch of random numbers in a loop for around
5 seconds. Enjoy!
""",
),
),
(
"Mapping Demo",
(
demos.mapping_demo,
"""
This demo shows how to use
[`st.pydeck_chart`](https://docs.streamlit.io/en/latest/api.html#streamlit.pydeck_chart)
to display geospatial data.
""",
),
),
(
"DataFrame Demo",
(
demos.data_frame_demo,
"""
This demo shows how to use `st.write` to visualize Pandas DataFrames.
(Data courtesy of the [UN Data Explorer](http://data.un.org/Explorer.aspx).)
""",
),
),
]
)
def run():
demo_name = st.sidebar.selectbox("Choose a demo", list(DEMOS.keys()), 0)
demo = DEMOS[demo_name][0]
if demo_name == "—":
show_code = False
st.write("# Welcome to Streamlit! 👋")
else:
show_code = st.sidebar.checkbox("Show code", True)
st.markdown("# %s" % demo_name)
description = DEMOS[demo_name][1]
if description:
st.write(description)
# Clear everything from the intro page.
# We only have 4 elements in the page so this is intentional overkill.
for i in range(10):
st.empty()
demo()
if show_code:
st.markdown("## Code")
sourcelines, _ = inspect.getsourcelines(demo)
st.code(textwrap.dedent("".join(sourcelines[1:])))
if __name__ == "__main__":
run()