Hacker News new | ask | show | jobs
by Wang0618 1917 days ago
Streamlit uses a responsive way to get input and doesn't rely on callbacks at all. Every time a user interacts with a widget, your script is re-executed and the output value of that widget is set to the new value during that run. It's amazing but also a little hard to understand.

In contrast, the way of writing PyWebIO app is more like writing a terminal program, except that the terminal here becomes a browser. The output functions will output content to user in real time, and the input functions will block until the user submit the input form.

2 comments

So, PyWebIO doesn't re-execute the whole script like Streamlit does? I use streamlit, and that's one of its pain points. If the script is complicated, re-execution becomes slow.

Also does PyWebIO support defining inputs based on other ones? For example, to have a hierarchy of dropdowns (select company --> based on that selection, select employee --> etc).

PyWebIO won't re-execute the whole script. In pywebio, if the code executes to the end, the user session will also be closed. You can use `while` loop in your code to continuously receive user input in PyWebIO app.

PyWebIO now support defining inputs based on other ones, but I haven't written this feature into the documentation. Until then, you can solve this problem by splitting inputs with dependencies into multiple forms. (you can use first form to get company and then use another form to get employee)

Excellent work, and thank you for sharing!

I see some immediate applications for this at my job. Much appreciation!