npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jupyter2svelte

v1.0.2

Published

Convert Jupyter Notebooks into Svelte Components

Downloads

4

Readme

Jupyter to Svelte

Convert Jupyter Notebooks into Svelte Components

Motivation

Jupyter Notebooks are great for exploratory data analysis, but they are not so great for sharing your work with others. This tool converts Jupyter Notebooks into Svelte components, which can be used in any Svelte application.

What's wrong with Jupyter's built-in conversion?

Jupyter's built-in conversion tool is great when you want to share a standalone file, be it markdown, HTML, or PDF. However, it doesn't work well when you want to have the notebook in a web application. For example, if you want to write a blog post in a Jupyter notebook, you can use this tool to convert the notebook into a Svelte component, which you can then use in your Svelte based web application.

Other reasons:

  • The markdown outputted by Jupyter doesn't play nicely with MDsveX
  • Jupyter's built-in tool doesn't support Plotly interactive charts
  • Custom styling
    • consistent look and feel across your web application
    • Want to use a PrismJS theme for code

Features

  • [x] PrismJS syntax highlighting for code blocks (Python only, R is not supported)
    • Assumes that a you have chosen a PrismJS theme and imported the css.
  • [x] Math displayed with KaTeX
  • [x] Interactive Plotly charts work out of the box
  • [x] Specify your own CSS/Scss/Sass style sheet for your notebook

Installation

Assuming you have Node.js installed:

npm install --global jupyter2svelte

Usage

Basic Usage

Pass the path to the Jupyter Notebook you want to convert as an argument to the convert command:

jupyter2svelte convert notebook.ipynb

This will create a new file called notebook.svelte in the same directory as the notebook which you can then import into your Svelte application.

The Svelte component will accept 1 or 2 props depending on whether or not you have any images in your notebook and whether or not you want to embed the images in the component:

  • img_alt_text - An array of strings that will be used as the alt attribute for the nth image. By default, the alt text will just be "Image".
  • img_path_prefix - The path to the directory where the images are stored, in a typical SvelteKit application you will place the images in the static directory and you would set this prop to "/" or "/some/folder/"
<script>
  import Jupyter from "./notebook.svelte";
</script>

<Jupyter img_path_prefix={"/notebook/"} img_alt_text={["Some Desc. of Graph 1", "Some Desc. of Graph 2"]}/>

If you choose to embed the images in your component, you can pass the --embed-images flag to the convert command and there will be no img_path_prefix prop. The images will be embedded in the component as base64 encoded WebP images.

jupyter2svelte convert --embed-images notebook.ipynb
import Jupyter from "./notebook.svelte";

<Jupyter img_alt_text={["Some Desc. of Graph 1", "Some Desc. of Graph 2"]}/>

All Options:

  • --style <style_sheet> Path to a CSS/Scss/Sass stylesheet to use
  • -q, --quality <quality> Specify the compression quality of the WebP images (default: "80")
  • -embd, --embed-images Embeds images in the component (default: false)
  • -h, --help display help

Specifying a Style Sheet

You can specify a style sheet to be applied to the notebook by passing the path to the style sheet as an argument to the convert command:

jupyter2svelte convert --style style.scss notebook.ipynb

Creating a Style Sheet

You can create a style sheet by hand from scratch, or you can use the default_css command to output the default style sheet and go from there.

jupyter2svelte default_css > style.scss

Classes:

| Class (all classes are attached to an outer div) | Description | | ------------------------------------------------ | ----------------------------------------------------- | | input | what was an input block in Jupyter (markdown or code) | | input-md | markdown block in Jupyter | | input-code | code block in Jupyter | | output | what was an output block from code in Jupyter | | output-text | standard text output (e.g. print statement output) | | output-html-table | pandas dataframes | | output-image | images (e.g. Matplotlib/Seaborn plots) |

Contributing

Contributions are welcome! Please open an issue or a pull request. If you want to contribute code, please make sure to run npm run format before committing.

Features that would be nice to have:

  • [ ] Support for other interactive plotting libraries (e.g. Bokeh)
  • [ ] Support for R notebooks?