Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions gallery/stream/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ def main():
# App
st.title("Stream")
st.header("A streamlit application template generator")

message = st.empty()

st.write('<hr>', unsafe_allow_html=True)

st.subheader("App location and name") # Directory section
dir_ = st.text_input(label="Directory where to create the app.\nUse '\\\\' instead of '\\'.")
st.write(dir_)

app_name = st.text_input(label="Name of your application.")

if app_name != "" and os.path.lexists(os.path.join(dir_, app_name)):
message.error("Directory already exists.")


# create temp directory for app - could be used for a future preview functionality
if os.path.lexists(os.path.join(wd_dir, "tmp")):
if os.path.lexists(os.path.join(wd_dir, "tmp", app_name))== False:
Expand All @@ -32,7 +39,7 @@ def main():
st.info(f'Current working directory: {wd_dir}')

st.subheader("App pages") # Pages section
page_num = st.number_input(label="Number of pages in your app")
page_num = st.number_input(label="Number of pages in your app", min_value=1)

st.write('<hr>', unsafe_allow_html=True)

Expand All @@ -48,17 +55,25 @@ def main():
page_elt.append(page_elt_holder)

if st.button("Create"):
struct.create_dir_structure(top_dir=dir_, name=app_name)

content.create_app_file(top_dir=dir_, name=app_name, pages=page_name)
content.create_default_pages(top_dir=dir_, name=app_name)

content.write_default_utils_functions(top_dir=dir_, name=app_name)
content.write_main_sidebar(top_dir=dir_, name=app_name, maintainer="Fred")

content.create_pages(top_dir=dir_, name=app_name, pages=page_name, elts=page_elt)

content.create_batch_file(top_dir=dir_, name=app_name)
if os.environ.get('AWESOME_STREAMLIT_ORG') != None:
message.info("AWESOME_STREAMLIT_ORG environment variable exists, application not created.")
else:
if app_name != "" and os.path.lexists(os.path.join(dir_, app_name)):
message = st.error("Directory already exists.")
else:
struct.create_dir_structure(top_dir=dir_, name=app_name)

content.create_app_file(top_dir=dir_, name=app_name, pages=page_name)
content.create_default_pages(top_dir=dir_, name=app_name)

content.write_default_utils_functions(top_dir=dir_, name=app_name)
content.write_main_sidebar(top_dir=dir_, name=app_name, maintainer="Fred")

content.create_pages(top_dir=dir_, name=app_name, pages=page_name, elts=page_elt)

content.create_batch_file(top_dir=dir_, name=app_name)

message = st.info("Created application!")



Expand Down
10 changes: 6 additions & 4 deletions gallery/stream/src/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ def create_app_file(top_dir, name, pages):
### IMPORT PAGES ###
f.write('import src.sidebar.main_sidebar as msb\n')
for p in pages:
f.write(f'import src.pages.{p} as {p}\n')
pr = p.replace(" ", "_")
f.write(f'import src.pages.{pr} as {pr}\n')

### DEFINE PAGES AS DICTIONARY ###
f.write('\n')
f.write('PAGES = {\n')
i = 1
for p in pages:
pr = p.replace(" ", "_")
if i != len(pages):
f.write(f'\t"{p}": {p},\n')
f.write(f'\t"{p}": {pr},\n')
else:
f.write(f'\t"{p}": {p}\n')
f.write(f'\t"{p}": {pr}\n')
i+=1
f.write('}')

Expand Down Expand Up @@ -57,7 +59,7 @@ def create_default_pages(top_dir, name, pages=PAGES_SRC):

def create_pages(top_dir, name, pages, elts):
for p,e in zip(pages,elts):
pp = p + ".py"
pp = p.replace(" ", "_") + ".py"
path = os.path.join(top_dir, name, "src/pages", pp)
with open(file=path, mode="w") as f:
f.write('import streamlit as st\n')
Expand Down
5 changes: 4 additions & 1 deletion gallery/stream/src/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
}

def create_dir_structure(top_dir, name, dir_list=DIRS):
if os.path.lexists(os.path.join(top_dir, name)) == False:

if os.path.lexists(top_dir) == False:
os.mkdir(top_dir)

if os.path.lexists(os.path.join(top_dir, name)) == False:
os.mkdir(os.path.join(top_dir, name))

for i in range(len(dir_list)):
Expand Down