15 Replies
That is an interesting problem. You mean you have global data you want to share between all kernels/browser-pages/users? Could you maybe explain what you try to do, that makes it easier for me to understand.
Also, how do you let the other browser pages update? Do you use your own event handling?
Whow, this certainly is simpler, but very magical (to me). Why does the second selectbox reset when the country changes?
When you change country, the list of cities changes (city_options is changed).
It seems the good folk at streamlit designed it so that a change in the option list implies that the old selection is no longer relevant. A good decision in my opinion.
See https://discuss.streamlit.io/t/st-selectbox-switches-back-to-default-when-options-list-changes/63820/3
Like many things in streamlit, it makes life for the programmer easier, but doesn't document them :-(.
Streamlit
St.selectbox switches back to default when options list changes
In my use case, that would not be an issue, but I see what you mean. How dangerous would it be to jump it back to the placeholder in that situation though? Also - this is not the case when format_func changes, as underlying values list then remains the same.
this is my web site,i use this to update my data such as daily route or to do list.
both PC and cellphone is my terminal
I am working on an intricate aspect of my web project that involves kernel initialization and the implementation of a daily auto-update schedule. To enhance the user experience, I have employed a threading tool that enables the site to load initially and then asynchronously fetch data. This approach has been successful in improving performance during the initial load phase and in managing regular updates.
However, I have encountered a challenge where multiple kernels attempt to initiate auto-updates simultaneously, leading to a system crash. To address this, I have integrated the threading mechanism into a global variable, which has provided me with the capability to monitor and manage these threads effectively.
Here is a snippet of the code that illustrates my approach:
---
@solara.lab.on_kernel_start
def pageinitial():
global bili,timer#这个全局变量的意思是超越了进程,那挺好的,本来我就只需要一个,但是获取不到进程里的响应变量数据,这部分又是跟着进程的。这样就混乱了。
if "bili" in globals():
bili.reset_solara_reactive()
#这个时候只要重新更新一次进程里的数据就可以,而不用重建立。
else:
bili=BILI_tools(DataSource,database_path,readed_fav_id,unread_fav_id,plan_fav_id,temp_fav_id,output_handler=print_ui,StandardMode=False)
timer1 = BiliTimer(bili.get_plan_list,1,1,1,hintmsg='开始加载计划清单',strmark='计划清单',threadname='izumik计划清单',output_handler=print_ui)
timer2 = BiliTimer(bili.get_todo_list,1.5,1.5,1,hintmsg='开始加载待办清单',strmark='待办清单',threadname='izumik待办清单',output_handler=print_ui)
df = checkthread() df=df[df['Name'].str.contains('计时器')] if df.shape[0]==0: timer = BiliTimer(bili.fav_to_database,scheduletime=scheduletime,threadname='izumik计时器'+datetime.datetime.now().strftime(timestring),output_handler=print_ui) bNeedinitial.value=False return timer.stop else: if not isinstance(timer, str): timer.next_run_time_ui.value=timer.global_next_run_time
return here is the snippet code of the page... it is also a little pit bother that jupyter has no kernel_start so I have to add some code for my develop enviroment and exclude them when deploying... @solara.component def Bili_console(): global bili,timer if "file" not in globals(): if bNeedinitial.value: bili=BILI_tools(DataSource,database_path,readed_fav_id,unread_fav_id,plan_fav_id,temp_fav_id,output_handler=print_ui,StandardMode=False) timer1 = BiliTimer(bili.get_plan_list,1,1,1,hintmsg='开始加载计划清单',strmark='计划清单',threadname='izumii计划清单',output_handler=print_ui) timer2 = BiliTimer(bili.get_todo_list,1.5,1.5,1,hintmsg='开始加载待办清单',strmark='待办清单',threadname='izumii待办清单',output_handler=print_ui)
#加一个检测,如果包含计时器,就不新建。
df = checkthread() df=df[df['Name'].str.contains('计时器')] if df.shape[0]==0: timer = BiliTimer(bili.fav_to_database,scheduletime=scheduletime,threadname='izumii计时器'+datetime.datetime.now().strftime(timestring),output_handler=print_ui) bNeedinitial.value=False
df = checkthread() df=df[df['Name'].str.contains('计时器')] if df.shape[0]==0: timer = BiliTimer(bili.fav_to_database,scheduletime=scheduletime,threadname='izumik计时器'+datetime.datetime.now().strftime(timestring),output_handler=print_ui) bNeedinitial.value=False return timer.stop else: if not isinstance(timer, str): timer.next_run_time_ui.value=timer.global_next_run_time
return here is the snippet code of the page... it is also a little pit bother that jupyter has no kernel_start so I have to add some code for my develop enviroment and exclude them when deploying... @solara.component def Bili_console(): global bili,timer if "file" not in globals(): if bNeedinitial.value: bili=BILI_tools(DataSource,database_path,readed_fav_id,unread_fav_id,plan_fav_id,temp_fav_id,output_handler=print_ui,StandardMode=False) timer1 = BiliTimer(bili.get_plan_list,1,1,1,hintmsg='开始加载计划清单',strmark='计划清单',threadname='izumii计划清单',output_handler=print_ui) timer2 = BiliTimer(bili.get_todo_list,1.5,1.5,1,hintmsg='开始加载待办清单',strmark='待办清单',threadname='izumii待办清单',output_handler=print_ui)
#加一个检测,如果包含计时器,就不新建。
df = checkthread() df=df[df['Name'].str.contains('计时器')] if df.shape[0]==0: timer = BiliTimer(bili.fav_to_database,scheduletime=scheduletime,threadname='izumii计时器'+datetime.datetime.now().strftime(timestring),output_handler=print_ui) bNeedinitial.value=False
I'm sorry, it really cannot tell from this what the problem is. If you can make an isolated example, it doesn't take me a lot of time to try to understand the problem, so I can focus on trying to find a solution.
is there a demo or best enviroment setting for jupyterlab with routes or layout?
i try to print some info but got nothing...
import solara
导入您的页面组件
from Module.P_BILI import app as P_BILI_Page
from Module.P_GPTOrder import app as P_GPTOrder_Page
from scripts import DailyRecorder as P_StatusRecord
from scripts import LoopRecorder as P_LoopRecord
定义路由
routes = [
solara.Route(path="/", component=P_LoopRecord.Page, label="P_Status"),
solara.Route(path="p_DailyRecord", component=P_StatusRecord.Page, label="p_DailyRecord"),
solara.Route(path="p_BILI", component=P_BILI_Page.Page, label="P_BILI Home"),
solara.Route(path="p_gptorder", component=P_GPTOrder_Page.Page, label="P_GPTOrder Page"),
]
@solara.component
def Page():
level = solara.use_route_level() # returns 0
route_current1= solara.use_router()
route_current, routes_current_level = solara.use_route()
print(level,route_current1.path,route_current,routes_current_level)
return P_LoopRecord.Page()
@solara.component def Layout(children): route, routes = solara.use_route() print(route,routes) dark_effective = solara.lab.use_dark_effective() return solara.AppLayout(children=children, toolbar_dark=dark_effective, color=None) # if dark_effective else "primary")
Layout([Page()]) the result None [] 3 None [] I put my token into a .env file and use load_dotenv() to load them, it worked in jupyterlab but not worked in solara run app.py (print out None), what should i do ?
@solara.component def Layout(children): route, routes = solara.use_route() print(route,routes) dark_effective = solara.lab.use_dark_effective() return solara.AppLayout(children=children, toolbar_dark=dark_effective, color=None) # if dark_effective else "primary")
Layout([Page()]) the result None [] 3 None [] I put my token into a .env file and use load_dotenv() to load them, it worked in jupyterlab but not worked in solara run app.py (print out None), what should i do ?
i don't think we do anything special that can interfere with that. what prints out None?
the example code:
file
.env
Notion API
NOTION_TOKEN=your_notion_token_here
DATABASE_PATH=your_database_path_here
from dotenv import load_dotenv
load_dotenv() key='NOTION_TOKEN' token = os.environ.get(key,config[key]) # this will use config token = os.environ.get(key) # this will be None in solara run mode while get values in jupyterlab mode print(token)
load_dotenv() key='NOTION_TOKEN' token = os.environ.get(key,config[key]) # this will use config token = os.environ.get(key) # this will be None in solara run mode while get values in jupyterlab mode print(token)
maybe the directory is not correct, print out os.getcwd() ?
part of os.environ
'C:\Windows', 'SOLARA_APP': 'Project_BILI_Tools/app.py', 'SERVER_NAME': '0.0.0.0', 'SERVER_PORT': '8848', 'MPLBACKEND': 'module://matplotlib_inline.backend_inline'})
os.getcwd()
C:\Users\A
deploy usaga way:
C:\Users\A>solara run Project_BILI_Tools/app.py --host=0.0.0.0 --port=8848
I host every project individually in base enviroment of anaconda.
such as
C:\Users\A\Project_BILI_Tools\app.py
and
C:\Users\A\Project_BILI_Tools\notebooks\BiliTools.ipynb
and the .env is at
C:\Users\A\Project_BILI_Tools.env
it got some trouble really ... when setting base sys path
if "file" in globals():
#cmd mode
current_dir = os.path.dirname(os.path.abspath(file))
else:
# Jupyter Notebook mode
current_dir = os.getcwd()
current_dir = os.path.join(current_dir, "..")
is there some best practice for this?
How mobile friendly is Solara?
Depends entirely on the implementation and what other libraries / widgets you want to use. It is possible to design things in a mobile friendly way in Solara, although it will take some familiarity with CSS.
It would likely be pretty vanilla Solara. This is helpful though - thank you.
For vanilla Solara it should be easier, since most components should deal fine with smaller widths/heights. If you run into any issues let us know!
Failed to load model class 'HtmlModel' from module 'jupyter-vuetify'
Error: Script error for "nbextensions/jupyter-vuetify/nodeps"
https://requirejs.org/docs/errors.html#scripterror
at makeError (http://localhost:8765/_solara/cdn/[email protected]/require.js:168:17)
----
I add some new module to my enviroments and solara server can't run ,how can i solve this problem?