Coder Social home page Coder Social logo

radames / jupyter_observable_widget Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 31 KB

Experiment embedding Observablehq notebook inside a jupyter notebook

Home Page: https://observablehq.com/@radames/umap-jupyter-notebook-scattergl

Jupyter Notebook 100.00%
observablehq jupyter-notebook jupyter observable-notebook

jupyter_observable_widget's Introduction

UMAP + Jupyter Notebook + ScatterGL

Open In Colab

Orignal notebook here https://observablehq.com/@radames/umap-jupyter-notebook-scattergl

Inspired by Thomas notebook visualize-a-data-frame-with-observable-in-jupyter

Could the dataframe be re-rendered inside jupyter and have observable updated the visualization?

You can read a discussion on the topic Observable Forum

Here is the Jupyter notebook source code and preview on google collab. Please change parameters and re-run cells to see it in action.

How it works

This Observable notebook is used as a reference vizualization. Using ScatterGL to plot 2D/3D points as a scatter plot.

You have to pass an array of 2D or 3D points to the HTML embed code. Then use Observable runtime to redefine the variables from your jupyter notebook.

Here is the jupyter python code with redifines. The data is serialize and dumped as string into the embed code.๐Ÿ˜› ย 

def make_viz_embed(data, colors = [], labels = []):
  embed = f"""
    <div id="observablehq-0842ed87"></div>
    <script type="module">
    import {{Runtime, Inspector }} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js";
    import define from "https://api.observablehq.com/d/8bcaee9a68db388d.js?v=3";
    const inspect = Inspector.into("#observablehq-0842ed87");
    const notebook = (new Runtime).module(define, name => (name === "containerEl") && inspect());
    notebook.redefine('points', {json.dumps(data)})
    notebook.redefine('colors', {json.dumps(colors)})
    notebook.redefine('labels', {json.dumps(labels)})
    </script>
  """
  return embed

jupyter_observable_widget's People

Contributors

radames avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.