-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
Panel-wrapped ipywidget does not display in Colab #6298
Comments
Hi. I ran into the same issue some weeks ago. In Developer tools console, your code shows error: Unable to find supported output mime type on {output_type: 'display_data', data: {…}, metadata: {…}, displayId: 'some_id', item_id: '4'} in output.binary.js:186. Just before that line, there is a codeblock that tests if the output is one of about 12 datatypes.
Apparently, output_type: 'display_data'does not match any of these data types? In addition, when I run
the console returns the above error, plus: IPyWidget model could not find a WidgetManager panel.min.js:124 and: Uncaught TypeError: Cannot read properties of undefined (reading 'set_log_level') VM414:212 , perhaps because bokeh server sets log_level to info? Console returns: [bokeh] setting log level to 'info' . and: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'set_state') panel.min.js:124 Running the below did not make a difference in any of the above errors.
A thread has been started for this topic here: Holoviz Discourse Hope this helps. |
I don't really know what's going on, but here's what I tried blindly:
It said
So I tried upgrading |
Thank you for trying! I have not been able to try the code in a standalone Jupyter Notebook, instead of in Colab. Do you have access to a Jupyter Notebook and could you do a quick test to see if it actually works in that setting? The link in Holoviz seems to imply that it should, but I have not been able to find any confirmation. From the link:
When running the below in Colab, a native panel slider is displayed succesfully when using pn.extension or pn.extension or pn.extension(inline=True, embed=True).
I can reproduce the error messages you mention. However, they only occur when (inline=True, embed=True) is added to pn.extension. When just doing pn.extension() it fails in the way I described in my earlier comment. From the link in Holoviz "The IPyWidget pane renders any ipywidgets model both in the notebook and in a deployed server. This makes it possible to leverage this growing ecosystem directly from within Panel simply by wrapping the component in a Pane or Panel." Do you have any idea what is meant by the above paragraph? The example in the link seems to imply that separately loading ipywidget_bokeh is not necessary. This is why positive confirmation that a minimal example actually works in a standard Jupyter Notebook installation would be great. Also, I found a mention somewhere else that pn.extension('ipywidgets') is not necessary anymore and that pn.extension() should suffice. I will try to find the source of that mention later. |
Thanks for confirming @pkumar0404! Helps a lot to have confirmation that wrapping ipywidgets works in Jupyter Lab. So the issue is defnitely Colab related. Could you possibly run this, or the below offical example again in your Jupyter Lab, and add pn.serve(layout), to confirm this also works when using panel as a web server, to serve (panel wrapped ipywidgets) to a webpage? So to confirm that a complete stack / combo of Notebook, Panel Widgets, wrapped ipywidgets , panel server is able to serve a Notebook with both types of components to a webpage. Panel component ipywidget full example Link to .ipynb Notebook used in the above page
This should return something like the below, clicking on the link should then display the layout object in a webpage. Launching server at http://localhost:XXXXX/ May I ask what your intended use case is for using Colab with panel and ipywidgets? PS In Colab the above pn.server(layout) results in the output as below, however the localhost does not resolve, because the Colab localhost is on the virtual machine that the Colab session runs in. But if a Jupyter Lab instance runs on a local machine, where one is allowed access to localhost, the above or http://127.0.0.1:XXXXX should show the page in a browser. |
Thanks @pkumar0404 ! I was hoping to leverage / re-use existing ipywidget objects, using panel to serve existing ipywidget objects alongside panel objects to a webpage (using among others Panel Tabulator, and Panel Perspective, which provides an almost spreadsheet-UI-like object with column filtering, grouping, editing, etc.). Regarding Excel tables: if it is relevant / an option for you to use Google Sheets (as an intermediate), Colab provides easy integration to Google Drive and Google Sheets. I have been able to easily import / read from Google Sheets, and export csv / other data / create / edit / update / spreadsheets in Google Sheets, using Python from within Colab. This should also work in Jupyter Lab. Nice extra option if you would want to publish data to a (web-based) spreadsheet environment, or from there export back to an Excel file. I used the Gspread Python library for this, which is based on the Google Sheets Python API. PS Are you on Discord? There is an interesting and lively Holoviz / Panel Discord Channel here. |
Thank you @Coderambling for your input. I have just started looking at Panel Tabulator as an alternative to Ipysheet, since we need to edit Dataframes in our app. I haven't had a chance to look at Panel Perspective as yet. |
Nice @pkumar0404 . See Perspective and example and screenshot below. Perspective is also editable. Just press the little pencil in the bottom right of the object to switch to editable. I think you can also control this programmtically. Also, you can do all kinds of Gui things in the object, including changing the theme to dark, downloading etc. Clicking the 3 little dots in the top left of the component toggles between UI + data and just data. Works in Colab. List of parameters of Perspective is here. Any thoughts on how to persist / save edits in components like Tabulator and Perspective during and between sessions? I am assuming (but not sure) taht edits in components lead to changing in the underlying dataframes, but how to handle updates / versioning/ consistency between users?
|
@Coderambling, our data is stored on MongoDB, both post-ingestion from Excel and modification in UI. We have a RESTful API for CRUD operations. |
Yes would be great! In fact, I am in discussion about it right now on Discord! Let me know if the link doesn't work Channel: https://discord.com/channels/1075331058024861767/1088157184489164831 |
Also, you HAVE to try this:
Then in the next cell: This automatically creates an output with a form with 2 tabs (Controls and layout), they both have a long list of fields with correct types, which lets you control all the parameters of the component through the form! For example in the Controls tab, there is the Theme dropdown field. Choose a theme from the list, and the component in the output of the previous cel changes it's theme instantly! The .controls() probably works for all Panel widgets! Just tried it with Tabulator, works as well. |
Hey @pkumar0404 are you still around? Did you manage to find the Discord Channel? Interesting stuff in there. I think I have an update on the Panel-wrapped ipywidget issue. |
Added warning that ipywidgets + Panel does not work in Colab. I think this should be pointed out in the documentation (I have wasted considerable time trying to get it to work, which is currently not possible due to Colab constraints regarding comms). Maybe even add a warning in the code that detects use of ipywidgets + Colab and provides a warning in the Cell output? See Discord message by @jbednar and surrounding messages here: https://discord.com/channels/1075331058024861767/1088157184489164831/1206732316513271818 And Github issue here: holoviz#6298 Added mention of Anaconda Cloud as a Notebook environment, and mention that users should upgrade Panel when using it. I am not sure what the correct / optimal !pip install command is. The specific command should probably be added, but at least this gives users a heads-up. Should Panel have code that checks its own version, and produces a warning if the latest version is not being used? That would seem sensible, also to alert users in local environments that are currently on the latest version, but might not be when the next version comes out. So this would provide them with a heads-up.
ALL software version info
Google Colab version as of 2024
Python 3.10.12
Panel 1.3.8
Ipywidgets 8.1.1
Description of expected behavior and the observed behavior
Combination of ipywidgets and panel does not display any output in Colab.
The combination works fine in Jupyter Lab.
Expected behavior on Colab is for the output to be shown.
Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
Screenshots or screencasts of the bug in action
The text was updated successfully, but these errors were encountered: