Do panel_conditional condition strings work withing modules? #2105
Answered
by
travis-leith
travis-leith
asked this question in
Q&A
-
|
I have the following function: def make_card(constraint_name: str, lb: float, ub: float) -> Tag:
sanitised_name = constraint_name.replace(".", "_")
return ui.card(
ui.card_header(ui.input_checkbox(f"{sanitised_name}_show", constraint_name, False)),
ui.panel_conditional(
f"input.{sanitised_name}_show == true",
ui.layout_columns(
ui.input_numeric(f"{sanitised_name}_lb", "Lower Bound", lb if lb != -np.inf else -1, step=0.01),
ui.input_numeric(f"{sanitised_name}_ub", "Upper Bound", ub if ub != np.inf else 1, step=0.01),
),
),
)My understanding is that if I convert this to a module, then a parameter that represents the constraint_name would be implicitly created, and all the ids would be part of a namespace given by that parameter. But the condition of panel_conditional is a string. Is it smart enough to know that "input.show == true" should be interpreted as "input.{constraint_name}.show == true"? |
Beta Was this translation helpful? Give feedback.
Answered by
travis-leith
Oct 22, 2025
Replies: 1 comment
-
|
To my amazement and satisfaction, this does in fact somehow work like magic @module.ui
def make_card(label: str, lb: float, ub: float) -> Tag:
return ui.card(
ui.card_header(ui.input_checkbox("show", label, False)),
ui.panel_conditional(
"input.show == true",
ui.layout_columns(
ui.input_numeric("lb", "Lower Bound", lb if lb != -np.inf else -1, step=0.01),
ui.input_numeric("ub", "Upper Bound", ub if ub != np.inf else 1, step=0.01),
),
),
) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
travis-leith
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To my amazement and satisfaction, this does in fact somehow work like magic