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

react-jupyter-notebook

v0.4.0

Published

A simple React component that renders .ipynb files just like how they are rendered by Jupyter Lab

Downloads

326

Readme

react-jupyter-notebook

A simple React component that renders .ipynb files just like how they are rendered by JupyterLab.

Demo: https://joeyonng.github.io/react-jupyter-notebook/

Why

I created this component because I want to embed a pure frontend jupyter notebooks (ipynb files) viewer into my personal website, which is built using React.

This project was inspired by React-Jupyter-Viewer. I still reinvented the wheel since I prefer the original looking of JupyterLab.

Install

npm install --save react-jupyter-notebook

Features

  • [X] Nearly identical looking to original JupyterLab interface.
  • [X] Can render codes, images, outputs, markdown(equations) and HTML in the notebook.
  • [X] Enable resizing the height of the scrolled output.
  • [X] Can change the alignment of the media outputs.
  • [X] Customisable code block styling.

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import JupyterViewer from "react-jupyter-notebook";
import nb_test from "./nb_test.json"; // You need to read the .ipynb file into a JSON Object.

ReactDOM.render(
  <React.StrictMode>
    <JupyterViewer rawIpynb={nb_test}/>
  </React.StrictMode>,
  document.getElementById('root')
);

Props

| Prop name | Type | Description | (default) Values | |-----------------|---------|-----------------------------------------------------------------|------------------------------------| | rawIpynb | Object | The JSON object converted from the .ipynb file. | | | language | String | The programming language used in the notebook. | "python", others | | showLineNumbers | Boolean | Show or hide the line numbers. | true, false | | mediaAlign | String | How to align medias (images, HTML). | "center", "left", "right" | | displaySource | String | How source cells are displayed. | "auto", "hide", "show" | | displayOutput | String | How output cells are displayed. | "auto", "hide", "show", "scroll" | | codeBlockStyles | Object | Customize code cells styles. Use JupyterLab theme if undefined. | undefined, {...} |

Customising code block styles (codeBlockStyles prop)

I use React Syntax Highlighter for the syntax highlighting. One little problem with React Syntax Highlighter is that the whole line number container cannot be separately styled. The line number part in the original JupyterLab theme has a different background color with the codes part, so they need to be separately styled. My solution is to use two <SyntaxHighlighter/> components: one displays line numbers, and the other displays codes themselves.

You can use codeBlockStyles prop to pass the props to the SyntaxHighlighter to customize your own code block styles. Please read the docs of React Syntax Highlighter if you want to use this prop.

| Property Name | Type | Description | Which <SyntaxHighlighter/> | |--------------------------|--------|----------------------------------------------------------|------------------------------| | hljsStyle | String | Name of the highlight.js style object. See here. | Both line number and code. | | lineNumberStyle | Object | Style object for every line numbers object. | Line number. | | lineNumberContainerStyle | Object | Style object for the container of line numbers. | Line number. | | codeContainerStyle | Object | Style object for the container of the codes. | Code. |