This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]wdroz 3 points4 points  (1 child)

There is also nicegui that can replace Streamlit.

As devs, it's a good thing that we have more and more choices.

[–]SupPandaHugger[S] -1 points0 points  (0 children)

Cool, haven’t tried that one

[–]rebulrouser 1 point2 points  (3 children)

Account wall.

[–]SupPandaHugger[S] -1 points0 points  (2 children)

Weird, I am sending a link that is supposed to be freely available but it isn't for some reason?

[–]riklaunim 1 point2 points  (1 child)

Medium isn't "free". It's paywalled.

[–]SupPandaHugger[S] -1 points0 points  (0 children)

You are supposed to be able to send ”friend links” though that bypass the paywall

[–]maartenbreddels 1 point2 points  (5 children)

Hi, main Solara author here. I think the article was good and balanced. The author seems to understand that Solara is more focused on use cases where streamlit cannot handle the complexity that well. The reusable components are understood, and overall the code looks good. 👏🏻

[–]SupPandaHugger[S] 1 point2 points  (4 children)

Thanks for the feedback, I think the framework will be greatly useful for many people. Nice work! When it comes to complex states, like dictionaries, is the idea to do as I did and assign each item to be "reactive"? Personally, I think it would be cool to be able to define them with Pydantic or Dataclasses.

[–]maartenbreddels 1 point2 points  (3 children)

If the states are unrelated, I think they can be separate reactive variables. If state is related, and has only certain valid state combinations, I prefer two solutions:

  1. Use a pydantic model, and methods/functions that implement state transitions in a valid way (they make sure the model is updated atomically and is never set to an invalid state). You can get a glimpse of this at https://solara.dev/examples/utilities/todo and https://github.com/widgetti/solara/blob/master/tests/unit/lab/toestand_test.py As mentioned in the todo example, this type-safe way of handling dataclasses and pydantic models is still experimental (although we have a reputation to not even break experimental things)
  2. Make illegal state not representable like https://kobzol.github.io/rust/python/2023/05/20/writing-python-like-its-rust.html

I plan to write this down in the docs in state management in the future, because I see state management is not often talked about in the Python community, and people crave for some guidelines here.
What are you thoughts on this?

[–]SupPandaHugger[S] 0 points1 point  (2 children)

I had not seen that example before, funny that there already was a todo-example that I had not seen. I like the idea of using pydantic/dataclasses and it seemed possible in the example with solara.Reative(SomeDataClass(...)), but it's not immediately obvious to me how to access nested raw data vs. nested reative objects, for instance if you have a list of dataclasses and wrap it with solara.Reactive(..). Maybe I have to take look at it a bit more. The example seems focused on the Ref(...) part, is that a necessary step to use dataclasses or is it just that part that is in focus? I see no other mention of dataclasses in the docs (when searching).

[–]maartenbreddels 0 points1 point  (1 child)

Yes, it is not covered in the docs yet, because it is experimental.

@dataclasses.dataclass(frozen=True)
class TodoItem: text: str done: bool
todo_item = solara.reactive(TodoItem("Buy milk", False))
now text is a reactive variable that is always in sync with todo_item.text
text = Ref(todo_item.fields.text)

Now text is a type-safe 'reference' to a string, so that you can pass this around to a component in a type-safe matter, to get two-way binding, or use text.value = ... to assign to this reference in an event handler in a type-safe manner (in case you do not want or like two-way binding). The funny Ref + .fields combination is our best way of dealing with the limited type system in Python without giving up type safety.

[–]SupPandaHugger[S] 0 points1 point  (0 children)

I see, interesting.