-
-
Notifications
You must be signed in to change notification settings - Fork 529
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
Support easy iterable layout #7570
Comments
Alternative ImplementationsCustom
|
I might be missing something, but to me, import param
import panel as pn
pn.extension()
class ForEachState(pn.viewable.Viewer):
colors: list[str] = param.List(
[
"red",
"green",
"blue",
"yellow",
"orange",
"purple",
]
)
def colored_box(self, color: str):
return pn.pane.Str(
color, styles={"background": color}, margin=0, width=50, height=20
)
@param.depends("colors")
def gridbox(self):
return pn.GridBox(*[self.colored_box(color) for color in ForEachState.colors], ncols=2)
def __panel__(self):
return self.gridbox()
ForEachState() Or equivalent pn.bind.
|
The points to me are
I think the main and overall point is that our code needs to be organized in a different order to most other frameworks which makes it harder to read and learn. I think the main reason is a missing feature. |
To me the import panel as pn
pn.extension()
class ForEachState(param.Parameterized):
colors: list[str] = param.List([
"red",
"green",
"blue",
"yellow",
"orange",
"purple",
])
def colored_box(color: str):
return pn.pane.Str(color, styles={"background": color})
state = ForEachState()
pn.Column(
pn.GridBox(objects=state.param.colors.rx.map(colored_box), ncols=2),
state.param.colors,
).servable() This seems pretty close to equivalent to the Reflex version of the code.
I'm not sure what this means.
Sure but neither can you do that in the reflex version correct? You can also still easily add more items:
|
'Objects' refers to the parameter name. I've never seen anyone use it. And the Docs warns against its usage. |
Can you point me to where? Because they definitely shouldn't. |
React and Reflex makes it easy to render a dynamic iterable:
See https://reflex.dev/docs/library/dynamic-rendering/foreach/.
With Panel you have to break out from the layout flow to create reactive functions to do this:
Please make this just as easy and readable as Reflex. Thanks.
The text was updated successfully, but these errors were encountered: