Giter VIP home page Giter VIP logo

vscode-jupyter-ipywidgets's Introduction

This folder is based off the the sample web3 from https://github.com/jupyter-widgets/ipywidgets/blob/master/examples/web3

  • We have built a custom solution based on web3 sample to host ipywidgets outside of Jupyter Notebook.

Warning

  • Most of the code has been copied as is from https://github.com/jupyter-widgets/ipywidgets/blob/master/examples/web3 & https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/html-manager/webpack.config.js.
    • Please try to minimize changes to original code to facilitate easier updatess.

Solution for IPywidgets

  • IPywidgets traditionally use requirejs.
    • traditionally as there seems to be some ongoing work to use commonjs2, though unsure how this will work with 3rd party widgets.
  • Using 3rd party widgets require:
    • requirejs to be available in the current browser context (i.e. window)
    • Base IPywidgets to be defined using define in requirejs.
  • Rather than bundling using amd or umd its easier to just import everything using commonjs2, then export for requirejs using define by hand.
    • define('xyz', () => 'a') is a simple way of declaring a named xyz module with the value a (using requirejs).
    • This is generally done using tools, however we'll hand craft this as it works better and easier.
    • amd is not what we want, as out react ui doesn't use amd.
    • umd is does not work as we have multiple entry points in webpack.
    • Heres' the solution define('@jupyter-widgets/controls', () => widgets);
  • We bundling the widget controls into our JS and exposing them for AMD using define
    • We could instead include https://unpkg.com/browse/@jupyter-widgets/[email protected]/dist/embed-amd.js
    • However this is a 3.2MB file.
    • Then our Widget manager also needs the widget controls. That would mean widget controls get included twice, once in our bundle and the other in the above mentioned embed-amd.js file.
    • Solution is to include everything thats in embed-amd.js into our bundle.
  • We need types for requirejs, but installing this into node_modules, for extension causes conflicts as we use require in standard node (extension and UI).
    • Solution is to just copy the @types/requirejs/index.d.ts into the types folder.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Directions for building

You might want to setup an npm link for the python repository

Then to build vscode-jupyter-ipywidgets

  • npm run download-api (updates vscode.d.ts)
  • npm run webpack (which will setup stuff for using with vscode-python)

Directions for debugging with jupyter extension

  • Run the steps above for getting the npm link setup
  • From with VS code, open both jupyter and lsp-middleware as two folders
  • Build the 'webpack link' task for lsp-middleware
  • Build the compile task for jupyter
  • Set breakpoints in the dist/node/index.js file while debugging (it's a development webpack)
  • Edit lsp code
  • Rerun the 'webpack link' build every time (it doesn't watch as it runs a post build step)

vscode-jupyter-ipywidgets's People

Contributors

dependabot[bot] avatar donjayamanne avatar microsoft-github-operations[bot] avatar microsoftopensource avatar rchiodo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

codeeditorland

vscode-jupyter-ipywidgets's Issues

Text widget not displayed

The displaying in vscode of a text widget from ipywidgets is not working for me. In my first cell I have

import IPython
import ipywidgets
import sys

print(IPython.__version__)
print(ipywidgets.__version__)
print(sys.version)

and the output is

8.5.0
8.0.2
3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]

In the next cell I have.

text = ipywidgets.Text(value="a")
IPython.display.display(text)

and that doesn't produce any output. Mimetype for that cell's output is "application/vnd.jupyter.widget-view+json". For reference, the cell

radiobuttons = ipywidgets.RadioButtons(options=["b", "c"], disabled=False)
IPython.display.display(radiobuttons)

produces the desired output, i.e., a pair of clickable radio buttons labelled "a" and "b". I've tried the same code with Python 3.8.13, same effect, and different orders for the cells, also same effect. My vscode is

Version: 1.72.0-insider (user setup)
Commit: 831678f718c8e998adc40d4854d9d35d9586a09f
Date: 2022-09-26T09:36:17.515Z
Electron: 19.0.17
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.25201
Sandboxed: Yes

Any clues? Thanks!

Passing python string variables to Javascript to set Ipywidget datepicker daterange

I am trying to pass python variables to Javascript inorder to set the max and min dates of my ipywidget date picker. the goal is to be able to set the time range based off the max and min date of a pandas dataframe. I get an error with the code below.

The error is ---
Javascript error adding output!
SyntaxError: Octal literals are not allowed in strict mode.
See your browser Javascript console for more details.

code ---
d= DatePicker(
description='pick Date',
disabled=False
)
d.add_class('java_d')

mindate = '2022-10-01'
maxdate= '2022-10-26'

script = Javascript("
const query = '.java_d > input: first-of-type';
document.querySelector(query).setAttribute('min', {};
document.querySelector(query).setAttribute('max', {};
".format(mindate,maxdate)
)

display(d)
display(script)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.