bashkernel

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package bashkernel implements tools to output rich content to a Jupyter notebook running the bash_kernel (https://github.com/takluyver/bash_kernel).

See usage example in gomlx/examples/cifar/demo.

Index

Constants

View Source
const BashNotebookEnv = "NOTEBOOK_BASH_KERNEL_CAPABILITIES"

Variables

This section is empty.

Functions

func EmbedImageSrc

func EmbedImageSrc(img image.Image) (string, error)

EmbedImageSrc returns a string that can be used as in an HTML <img> tag, as its source (it's `src` field) -- without requiring separate files. It embeds it as a PNG file base64 encoded.

func IsBashNotebook

func IsBashNotebook() bool

IsBashNotebook returns true if NOTEBOOK_BASH_KERNEL_CAPABILITIES is set, which indicates it is running from within a Notebook.

func OutputHTML

func OutputHTML(html string, displayId string) error

OutputHTML outputs the html content such that it gets displayed on a Jupyter(Lab) Notebook, using the bash_kernel.

If displayId is set (displayId != ""), and a cell with the same displayId was created (and not deleted) earlier, it will update the contents of the same cell. Useful for updating dynamic content.

Notice that if the cell is re-run the cell disappears and cannot be updated. Hence, a new unique displayId should always be created at the first use time. Also, displayId's shouldn't be shared with different types of content.

func OutputJavascript

func OutputJavascript(javascript, displayId string) error

OutputJavascript sends the javascript content to be executed on a Jupyter(Lab) Notebook, using the bash_kernel.

If displayId is set (displayId != ""), and a cell with the same displayId was created (and not deleted) earlier, it will update the contents of the same cell. Useful for updating dynamic content.

Notice that if the cell is re-run the cell disappears and cannot be updated. Hence, a new unique displayId should always be created at the first use time. Also, displayId's shouldn't be shared with different types of content.

func OutputToPrefix

func OutputToPrefix(prefix BashKernelNotebookPrefix, content string, displayId string) error

OutputToPrefix saves the given content in a temporary file and outputs a prefixed line pointing to the file. If displayId != "", displays using that id.

Types

type BashKernelNotebookPrefix

type BashKernelNotebookPrefix string
const (
	// HTMLPrefix indicates the file that follows holds HTML content to be displayed.
	HTMLPrefix BashKernelNotebookPrefix = "bash_kernel: saved html data to: "

	// JavascriptPrefix indicates the file that follows holds Javascript content to be executed.
	JavascriptPrefix = "bash_kernel: saved javascript data to: "
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL