I am trying to add a widget dynamically to a column. I found this old post on StackOverflow but it doesn’t work.
The issue is that column(children=[…]) returns type Column and the children method in Column is of type List[UIElement] and it does not support append or insert methods like a Python list. Perhaps the Bokeh list type was introduced after the SO post.
Am I doing something incorrectly here? Is there another/better way to do dynamic insertion of widgets? I am coming from Shiny Python and looking for the equivalent of ui_insert.
@kampai-shp In fact, the code you have above works just fine. You will need to provide more details about the specifics of your situation, including any actual error message, how exactly you are running things, and most especially, all relevant version information.
Thanks for the quick response, Bryan. I see now that it does work, despite flagging in Pylance in VSCode:
Cannot access attribute "append" for class "List[UIElement]"
Attribute "append" is unknown Pylance (reportAttributeAccessIssue)
(function) append: Unknown
This typing error usually means the attribute doesn’t exist and the code won’t run. I’ll #type ignore it.
What is Bokeh’s process for getting type checkers to recognize custom Bokeh types? Another one is having the “active” attribute of RadioButtonGroup return a Nullable[int]. It also flags in Pylance.
Bokeh’s custom property descriptors predate tools like MyPy, but provide extensive and important features (automatic validation, serialization, docs integration, as well as more types that are not otherwise expressible) that make it unfeasible to simply move away from them. So it’s not an ideal situation in the context of contemporaty tooling. There are some ongoing efforts to try and improve things, feel free to chime in any specific issues for motivation.