Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5ebee8d6ec | |||
| f1f74f3067 | |||
| 2f90a83737 |
@@ -3,8 +3,21 @@ import os
|
|||||||
import streamlit as st
|
import streamlit as st
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from app.core import settings
|
st.set_page_config(
|
||||||
|
page_title="Leo's Demo App",
|
||||||
|
page_icon="🧊",
|
||||||
|
layout="wide",
|
||||||
|
initial_sidebar_state="expanded",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@st.cache_resource
|
||||||
|
def get_settings():
|
||||||
|
from app.core import settings
|
||||||
|
return settings
|
||||||
|
|
||||||
|
|
||||||
|
settings = get_settings()
|
||||||
pages = os.listdir(os.path.join(settings.BASE_DIR, 'pages'))
|
pages = os.listdir(os.path.join(settings.BASE_DIR, 'pages'))
|
||||||
pages = [{
|
pages = [{
|
||||||
'filename': page,
|
'filename': page,
|
||||||
@@ -12,13 +25,6 @@ pages = [{
|
|||||||
} for page in pages if page.endswith('.py') and page != '__init__.py']
|
} for page in pages if page.endswith('.py') and page != '__init__.py']
|
||||||
pages.sort(key=lambda x: x['filename'])
|
pages.sort(key=lambda x: x['filename'])
|
||||||
|
|
||||||
st.set_page_config(
|
|
||||||
page_title="Leo's Cool App",
|
|
||||||
page_icon="🧊",
|
|
||||||
layout="wide",
|
|
||||||
initial_sidebar_state="expanded",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def open_selected_file():
|
def open_selected_file():
|
||||||
with open(st.session_state.page_file['filepath'], 'r', encoding='utf-8') as f:
|
with open(st.session_state.page_file['filepath'], 'r', encoding='utf-8') as f:
|
||||||
@@ -30,6 +36,7 @@ def save_file_content():
|
|||||||
with open(st.session_state.page_file['filepath'], 'w', encoding='utf-8') as f:
|
with open(st.session_state.page_file['filepath'], 'w', encoding='utf-8') as f:
|
||||||
logger.debug(f"save: <\n{st.session_state.file_content}\n>to file {st.session_state.page_file['filepath']}")
|
logger.debug(f"save: <\n{st.session_state.file_content}\n>to file {st.session_state.page_file['filepath']}")
|
||||||
f.write(st.session_state.file_content)
|
f.write(st.session_state.file_content)
|
||||||
|
st.toast('保存成功!', icon='🎉')
|
||||||
|
|
||||||
|
|
||||||
def new_file():
|
def new_file():
|
||||||
@@ -3,3 +3,8 @@
|
|||||||
## 1. 项目介绍
|
## 1. 项目介绍
|
||||||
|
|
||||||
通过 streamlit的多页面应用, 实现多demo的动态展示
|
通过 streamlit的多页面应用, 实现多demo的动态展示
|
||||||
|
|
||||||
|
|
||||||
|
实际上是可以在web页面里, 编写streamlit页面代码, 直接查看效果.
|
||||||
|
|
||||||
|
用streamlit页面编辑新的streamlit页面, 就简单称为自举了(可能不太恰当)
|
||||||
10
pages/first_demo.py
Normal file
10
pages/first_demo.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
import streamlit as st
|
||||||
|
|
||||||
|
st.write('# Hello World!')
|
||||||
|
|
||||||
|
st.link_button("Go to gallery", "https://streamlit.io/gallery")
|
||||||
|
|
||||||
|
for i in range(5):
|
||||||
|
st.write(f"{i + 1}. this is line {i + 1}")
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding:utf-8 -*-
|
|
||||||
import streamlit as st
|
|
||||||
|
|
||||||
st.write('Hello World!')
|
|
||||||
|
|
||||||
for i in range(1, 13):
|
|
||||||
st.write(f"{i}. this is line {i}")
|
|
||||||
@@ -1 +1 @@
|
|||||||
streamlit run --server.port 5280 --server.enableCORS false ./main.py
|
streamlit run --server.port 5280 --server.enableCORS false ./Home.py
|
||||||
Reference in New Issue
Block a user