How To: Resolve Add-on Mode Not Rendering, but Notebook is
Overview
Users can sometimes encounter an issue where their Add-ons work flawlessly when executed in Classic Notebook mode but exhibit unexpected behavior when switched to Add-on Mode.
The problem can be demonstrated by considering a simple notebook containing a Python class with a header and a button. When the button is clicked, a specific action should be displayed on the page. In Classic Notebook mode, this functionality works as expected. However, when the same notebook is executed in Add-on Mode, the button click fails to produce the desired output. Although the button is being clicked, nothing is being displayed on the screen.
This discrepancy in behavior can be attributed to an upgrade that occurred when Data Lab was updated to include an Advanced Mode (JupyterLab). As part of the upgrade, the rendering process for Add-on Mode was enhanced by integrating Voila, a tool that transforms Jupyter Notebooks into standalone Add-ons. However, it has been identified that Voila contains a known bug, documented as
https://github.com/voila-dashboards/voila/issues/532 , which prevents the proper rendering of certain embedded ipywidgets on the screen.
Unfortunately, the timeline for resolving this bug in Voila is uncertain. However, there is a straightforward solution available that can rectify the issue and ensure the Add-on functions as expected.
The subsequent sections of this document present the solution to this problem, involving a minor modification to the script that accommodates the Voila bug. By following the recommended changes, users can successfully overcome the rendering issue and achieve the desired functionality of their Add-ons in both Classic Notebook mode and Add-on Mode.
Classic Jupyter Notebook | Add-on Mode |
---|---|
Solution
To address the rendering issue caused by the Voila bug and ensure the proper functionality of Add-ons in both Classic Notebook mode and Add-on Mode, a simple modification needs to be made to the script. The solution involves incorporating the use of the ipywidgets.Output()
widget— https://ipywidgets.readthedocs.io/en/7.7.0/examples/Widget%20List.html?highlight=Output#Output .
In the original code, the ShowWidget
class defines a button and a header within the self.box
widget. When the button is clicked, the onBtnClick()
function attempts to display the action on the screen. However, due to the Voila bug, the display is not rendered correctly in Add-on Mode.
To resolve this, the script should be adjusted by introducing an output
widget of the ipywidgets
module. This widget serves as a designated location for rendering the button click. The modified code includes the following changes:
The
self.output
widget is created and added to the widget hierarchy by including it in theself.box
widget alongside the header and button widgets.The
onBtnClick()
function is updated to use theself.output
widget for rendering. The button click is wrapped within awith
statement that directs the output to theself.output
widget.Finally, the modified script ensures the proper display of the Add-on by invoking the
display(self.box)
function.
Doesn’t Work in Add-on Mode | Works in Add-on Mode |
---|---|
PY
|
PY
|
By implementing these changes, the Add-on will function correctly in both Classic Notebook mode and Add-on Mode. The self.output
widget acts as the designated rendering area for displaying the action when the button is clicked. This solution effectively mitigates the rendering issue caused by the Voila bug and guarantees consistent behavior of the Add-on across different Seeq versions.
Add-on Mode After Modification |
---|