knowledge-repo icon indicating copy to clipboard operation
knowledge-repo copied to clipboard

ipywidgets not rendering in posts

Open dhango opened this issue 8 years ago • 8 comments

Auto-reviewers: @NiharikaRay @matthewwardrop @earthmancash @danfrankj

Hi! I'm trying to render an interactive textbox via ipywidgets with the following code.

import ipywidgets as widgets
from IPython.display import display

text = widgets.Text(
    value='',
    placeholder='',
    description='Query:',
    disabled=False
)

# print(text)

display(text)
text.on_submit(handle_submit)

The textbox appears in my notebook but does not appear in the knowledge repo. When I print the text object I get

<ipywidgets.widgets.widget_string.Text object at 0x7eff10343438>

even though nothing is rendered. Wondering if ipywidgets objects are supported? Does it have something to do with having to enable an extension (jupyter nbextension enable --py --sys-prefix widgetsnbextension) for the rendering to work?

Any help here would be greatly appreciated! Thanks!

dhango avatar May 19 '17 19:05 dhango

Hi @dhango

We recently made some changes regarding support for javascript in knowledge posts, which may have fixed this issue too. Can you check whether the master branch still has this issue? If so, we'll look into it at some point :).

Thanks for reporting it!

matthewwardrop avatar May 25 '17 04:05 matthewwardrop

Thanks for getting back @matthewwardrop !

I checked the master branch and ipywidgets still do not render. I tried creating the text box in pure JS and that rendered fine, so this may be something specific to ipywidgets. I really appreciate the help!

dhango avatar May 26 '17 00:05 dhango

@dhango ipywidgets rely on the python kernel backend being present so they won't with the knowledge_repo the way you are hoping (I think). The best you would get is the JS controls that don't do anything similar to what you see here: https://nbviewer.jupyter.org/github/jupyter-widgets/ipywidgets/blob/2940f9f56f63257902b27509f18e872e77c3c014/docs/source/examples/Widget%20Basics.ipynb

bmabey avatar May 26 '17 16:05 bmabey

Hey,

I was wondering if this issue has been worked on this it was submitted? Do the ipywidgets render now?

Thanks

robertdefilippi avatar Jan 29 '19 14:01 robertdefilippi

I'm also wondering whether it's possible for KR to support ipywidgets.

jpzhangvincent avatar Jul 27 '20 06:07 jpzhangvincent

@robertdefilippi @jpzhangvincent I believe for ipywidgets to work in the knowledge repo, the widgets would need to be translated to pure JS as @dhango suggested.

Internally at Airbnb, we have already done this for .Rmd notebooks with an R package, but I don't think we have a solution for Python yet. If you submit a PR for this happy to review and merge.

bulam avatar Jul 30 '20 04:07 bulam

@bulam I'm wondering whether Plotly charts in jupyter notebook with R kernel would be properly rendered.

jpzhangvincent avatar Sep 14 '20 01:09 jpzhangvincent

@jpzhangvincent that's an interesting question. Haven't tried this!

bulam avatar Sep 25 '20 04:09 bulam