-
-
Notifications
You must be signed in to change notification settings - Fork 695
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
Blank page #72
Comments
Hi, thanks for reporting this issue! I think I can explain what is going on an how to fix your example. By default NiceGUI starts a uvicorn server with auto-reload activated. This already happens during import and that's why the main script (run.py in your case) blocks within You can either remove the main guard or at least move With some clean up here and there, this is your resulting code: repr_layer.py from nicegui import ui
def add_elements(container):
with container:
result = 'something'
ui.label(result)
def initialize_ui():
ui.label('Any label')
row = ui.row()
ui.button('+', on_click=lambda: add_elements(row))
return ui run.py from repr_layer import initialize_ui
if __name__ == '__main__':
ui = initialize_ui()
ui.run(reload=False) Notes:
Let me drop a few thoughts about the OOP design decisions you mentioned. Implicit nesting via scopes We wanted NiceGUI to be an intuitive API for creating user interfaces. UIs are typically hierarchically organized and markup languages like HTML reflect that visually: <div id="container">
<div id="box">
<p>Hello world!</p>
</div>
</div> That's why we wanted a UI description with NiceGUI to have a similar form: with ui.card():
with ui.row():
ui.label('Hello world!') JustPy, on the other hand, becomes tricky to read when nesting UI elements: container = Div()
box = Div()
label = Div(text='Hello world!')
box.add(label)
container.add(box) (Sure, you could create some objects inline. But if you need their references, it clutters quickly.) Thus, with NiceGUI you don't create hierarchy via Constructors as functions with side-effects A function like Again, compared to an approach like JustPy, we think NiceGUI is more convenient. Comparison to Streamlit Streamlit and its weird control flow was actually the motivation for us to write NiceGUI. See #21 for a more detailed discussion. |
Thank you for the details. I tested both ways out. Not workingWith the reloading disabled a web server isn't getting started. from repr_layer import initialize_ui
if __name__ == '__main__':
ui = initialize_ui()
ui.run(reload=False) WorkingWith the main guard removed it works. That's my choice. Comment on the concept
You know, it's quite intuitive and i like this approach, but let me ask you why do we use with ui.card() as card:
with card.row() as row:
row.label('Hello world!') Now, from an html perspective, i see adding subelements as follow: <body> <!-- let's suppose that's `ui` element -->
<subelement> <!-- code line such as `with ui.row(): ui.subelement()` in my mind is placed here and it is NOT correct-->
<div id="container">
<div id="box">
<p>Hello world!</p>
<subelement> <!-- would code line `with ui.row() as row: row.subelement()` in your mind places an element here? -->
</div>
</div>
</body> Anyway, i enjoy Nicegui. Get my comment as a review only 🙂 |
The "not working" example using Regarding your comments on our concept: Thanks for the interesting thoughts! It's quiet fun to juggle with the different possibilities a languange like Python gives you to create an API. Let me elaborate a bit on your example: with ui.card() as card:
with card.row() as row:
row.label('Hello world!') I see your point. The with ui.scene() as scene:
scene.sphere() So introducing a new 3D object with ui.card() as main_card:
with card.row() as info_row:
info_row.label('Time:')
info_row.label('CPU%:')
info_row.label('RAM%:')
with card.row() as button_row:
button_row.button('Start')
button_row.button('Pause')
button_row.button('Stop') Repeating the container names is pretty verbose, given the indentation already defines the hierarchy. Sure, you could use names like Besides that, your approach would clutter the namespace of, e.g., a card: Is |
Well, i pretty understand avoidance of verbosity, var names cluttering and building UIs through >>> import this
The Zen of Python, by Tim Peters
...
Explicit is better than implicit.
... I think if you mention the concept with a few details in the documentation(your explanation above, for example) it would keep people away of being a bit confused on it as they can follow the idea. I mostly mean a python developers category. |
Problem
Well, i read the source code and have many words to say. In short, i don't understand the concepts you implemented in terms of OOP.
What i'd like to have is to organize my project with importing
ui
object from a module of initializing all the elements and some application logic which adds a few new elements after a request to a DB. Then call methodui.run()
in a top level module. This approach shows a blank page.If i keep
ui
object in one module everything is working, but it's a bad practice and in my case i tooknicegui
as a fast WUI builder for a representation layer over some logic in application layer.Pseudo code to explain
repr_layer.py
run.py
And nothing is displayed here, but a server is running normally.
Expectations
Hope
nicegui
can be used along with some custom logic beside WUI implementation? Or it's not intended for such cases by design and better to takejustpy
orstreamlit
, for exmaple?The text was updated successfully, but these errors were encountered: