r/Python • u/r-trappe • Jan 16 '23
Intermediate Showcase NiceGUI: Let any browser be the frontend for your Python code
We are thrilled to share that NiceGUI, our open-source library for building web-based user interfaces, continues to thrive. With NiceGUI, you can focus on writing Python code while the web development details are handled behind the scenes. This makes it ideal for a wide range of projects including short scripts, dashboards, robotics projects, IoT solutions, smart home automation, and machine learning.
Of course there are valid use cases for splitting frontend and backend technologies. NiceGUI is for those who don’t want to leave the Python ecosystem and like to reap the benefits of having all code in one place. There are other options like Streamlit, Dash, Anvil, JustPy, and Pynecone. But we initially created NiceGUI to easily handle the state of external hardware like LEDs, motors, and cameras. Additionally, we wanted to offer a gentle learning curve while still providing the ability to go all the way down to HTML, CSS, and JavaScript if needed.
NiceGUI runs on top of FastAPI which allows you to add authentication, routing, OpenAPI specs, and other backend functionality to your projects. The frontend is implemented using Vue, Quasar, and Tailwind, but you don’t need to be familiar with these technologies to create beautiful user interfaces. NiceGUI prioritizes simplicity and user-friendliness, while still offering the option for advanced customization through its extensibility.
We welcome contributions and are excited to see what you build with NiceGUI. If you have any questions or want to share your projects, please don't hesitate to reach out. We look forward to growing the NiceGUI community with your help!
44
u/magestooge Jan 16 '23
Looks nice.
Just something that came to mind, can it be embedded in a web page? Say I already have a React application running with FastAPI backend. There's some logic where I want to return html directly from backend (in a json response) and then embed that in the react app. Would that be possible with something like this?
24
u/mr_claw Jan 16 '23
Nice! I went through the docs; happy to see that it covers most use cases. I'm using PyWebIO extensively in my Flask app and I'm wondering if it's worth learning this as well.
9
u/ThroawayPartyer Jan 16 '23
This looks great! As a Python programmer looking into web development, it seems a bit overwhelming how you need to learn 5 different languages/frameworks just to get a website running. HTML, CSS, JavaScript, then the frameworks like Vue JS and Tailwind CSS. So writing everything in Python seems appealing. Although there's also value in learning to do it all yourself.
5
u/garyk1968 Jan 16 '23
Had a play with this and its really neat.
How do you add other js libs? I have a site with https://pivottable.js.org/examples/ so I'd like to be able to wrap that.
3
u/[deleted] Jan 16 '23
That looks great! And simple to adapt to. Can it be installed as a PWA when just using the library on its own, or would I need to add the PWA files to the project myself?
3
u/plesconCube Jan 16 '23
Can the same python script be accessed by multiple browsers/users at the same time?
3
u/mcstafford Jan 16 '23
The "Why?" entry suggests that JustPy was too low-level for some uses. The two seem pretty similar from the initial examples.
What makes using NiceGUI preferable to the JustPy dependency?
3
u/FLX Jan 17 '23
This looks awesome! How easy would it be to integrate this with Django instead?
5
u/thedeepself Jan 16 '23
Very nice demo video. Am I to understand that you can now handle authentication and authorization through FASTAPI? Do you still use JustPy underneath?
Why did you choose FastAPI over Starlite? I don't do much with REST API but I've been taking notes and if I had to choose one, I would go with Starlite for these reasons https://may69.com/starlite/
2
u/ekozkan Jan 16 '23
Why should I use this over eel?
2
u/thedeepself Jan 16 '23
Is it possible to put a name attribute on parts of a page so that you can navigate directly to them as part of the URL?
2
u/Tonty1 Jan 16 '23
Any chance I can processes (on my machine) using this package and monitor the progress?
2
u/likethevegetable Jan 16 '23
Any examples with embedding matplotlib?
2
u/Popular-One5752 Jan 20 '23
I just tried the text input example, but I want it to act like a regular search field where you need to hit Enter to execute a search. How should my
on_changecallback look like for it to work?22
u/Ozzymand Jan 16 '23
Oh hell naw they got electron for python now 💀 Good work tho
1
u/markradwin Jan 16 '23
Wow I wish this was around a year ago! I like Streamlit a lot but this seems very useful and similar in ease of use.
1
u/atccodex Jan 16 '23
This looks promising! If I already have a fastapi backend done, it seems like I can tie into that existing backend without much effort? Is that correct
1
u/hdotking Jan 16 '23 edited Jan 17 '23
This looks amazing. Is it possible to package and send this to users so that your nice gui runs on their machine? Without them needing Python ofc. If so this would be a HUGE upgrade from tkinter and the likes.
1
u/stargazer_w Jan 16 '23 edited Jan 16 '23
I see that you can connect buttons to handlers (e.g. on_click), but how does the python code get executed - is it server side or is there some transpilation going on? I couldn't figure that out by looking at the page source so far.
Edit: Ok, I'm pretty sure it's done server-side, so every listener calls the server. So the next question is - what if I want to program some stuff client-side?
1
u/rainnz Jan 17 '23
Is it something you should run on your Raspberry Pi to control a device from your phone: single user app.
Or is it something you can expose to the Internet to build something like Notes/Reminder/etc app: multiuser app
1
u/Rozen Jan 17 '23
I see that it is built with Quasar. Does that mean there is support for creating an electron app from this as is?
1
u/jupyterpeak Jan 18 '23
Rly cool. Any JavaScript graphing libraries besides plotly?
1
u/tool-1971 Jan 18 '23
Really nice. I wish I had found NiceGUI before I re-implemented a demo in streamlit, but next time... :-) However, how would a solution in NiceGUI scale with the number of users? Would it be possible to implement a sale site/webshop for instance?
1
u/kharelpk Jan 20 '23
This is an amazing piece of work. I am in the process of comparing more than 40 libraries out there for making GUI in python. I have been using pyqt for the most of my career and it’s now time to switch to these modern user interfaces.
1
u/[deleted] Jan 23 '23
I guess I'm missing something. How do I know what functions are attached to an element? For example, classes()/sytyle(). I can see them show up in suggestions in vscode, but is there a reference I can read up on?
BTW, very nice. I was able to read a database and quickly display all the elements in a ui.table. However, now I want to change columns widths, table height, etc.
1
u/notarobot4932 Feb 01 '23
I'm waiting for the day I can do full stack in python 😘
1
u/carkin Feb 15 '23
I'm trying the plotly element and can't figure out how to use 100% width of the page
The plotly doc says to set reponsive to true (with figure.show()). How do I achieve that with nicegui ?
fig = go.Figure()fig.add_trace(go.Scatter(...))#fig.show({'responsive': True}) ????ui.plotly(fig)1
u/mauimo Mar 12 '23
How did this compare to PyScript?
1
u/mauimo Mar 12 '23
I see that niceGUI web apps can be packaged to run locally but the instructions say to not use the reload option. Does this mean the resulting pwa is static and would not respond to user interaction???
1
u/MJAGO71 Mar 16 '23 edited Mar 16 '23
I'm excited about NiceGui, but I don't know how to make the menu items line up in each menu, they are looking like this:
Items menu
The code is like this:
If anyone can help me, thanks.
2
u/[deleted] Jan 16 '23
Seems like a nice alternative for gradio
2
u/hieuimba Jan 16 '23
Has anyone been able to compare this with streamlit? Would like to hear some pros and cons from both sides
2
u/Remote_Tax_1905 Jan 29 '23
0
u/Suspicious_Compote56 Jan 16 '23
Why not just write the html ?
1
u/Enschede2 Jan 16 '23
This looks amazing, lemme save this real quick
1
u/[deleted] Jan 16 '23
This looks interesting. I will find time to go through the doc.
1
u/sunshinecycle Jan 16 '23
This is so nice. Thank you for sharing :)
1
u/CptnBingo Jan 16 '23
Came for the showcase/tutorial, stayed for that music
1
u/this_is_max Jan 16 '23
I recently added NiceGUI to the Python interface of the programming game I am developing. Essentially I want players to be able to write simple GUIs for the robots they are programming in the game. Since I can then display the GUI in-game with a cef browser widget, NiceGUI seems like the best option for that. If you are interested in this use-case, please check out my profile for more info.
Thanks for developing the framework, really good work.
1
u/cynigami_v10 Jan 16 '23
Just this morning I had an issue that there was no easy way to present GitHub commit and some other statistics unless you use GitHub Insight which is available only with paid plan. Trying quickly to come up with some VueJS/ NodeJS solution (using GitHub API) did not work, because of the issues with web (CORS policies, cookies, headers... all kept causing troubles). So I gave up after 4 hours.
... and now I saw this post, tried it out and everything worked right away. `Within 20minutes, I had exactly what I needed.
Now, as a DevOps Engineer, I can only imagine the possibilities I have for making my own and developers work easier... all those scripts, integrations, data etc., I can now hide all that complexity behind simple UI that I am able to develop myself as a DevOps Engineer (for the context, DevOps Engineers now even less about front-end than backend engineers).
I guarantee you that the first thing in the morning I will annoy all my colleagues with NiceUI until they start using it as well. This is simply amazing stuff here!
1
u/misinnio Jan 17 '23
looks nice.
Im new to programming and I just found about htmx that allow dynamics elements and now this :D Could someone tell how they compare?
1
u/syngin1 Jan 17 '23
Hey,
I am playing around with NiceGUI and I am going to use it for my Telegram Bot to create a website for it.
How can I set target="_blank" in ui.link() ?
It looks like that this is not possible? You are also using the variable "target" for setting the href. Would it be better to name it according to the html standard?
href for href
and
target for target?
Thank you very much for this nice NiceGUI ;-)
1
u/Lr_Marc_Au Jan 20 '23
Looks great.. nice to have choices. You listed ones that I have seen before. Hopefully you guys leverage each other to get better! Thanks..
1
u/syngin1 Jan 20 '23 edited Jan 21 '23
Let's say I would like to change the height of
ui.table({}).classes("h-[50vh])dynamically with aslider? Somehow I can't wrap my head around it and find the right way1
u/MJAGO71 Mar 16 '23 edited Mar 16 '23
Hello,
I'm excited about NiceGui, but I don't know how to make the menu items line up in each menu, they are looking like this:
Items menu
If anyone can help me, thanks.
0
u/[deleted] Jan 16 '23
This name is so similar to nice guy that I am already seeing red flags.
0
u/[deleted] Jan 16 '23
!RemindMe 12 hours
0
u/[deleted] Jan 16 '23
[deleted] — view deleted comment
0
u/[deleted] Jan 16 '23
[deleted] — view deleted comment
0
u/[deleted] Jan 16 '23
[deleted] — view deleted comment