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
- func EmbedImageSrc(img image.Image) (string, error)
- func IsBashNotebook() bool
- func OutputHTML(html string, displayId string) error
- func OutputJavascript(javascript, displayId string) error
- func OutputToPrefix(prefix BashKernelNotebookPrefix, content string, displayId string) error
- type BashKernelNotebookPrefix
Constants ¶
const BashNotebookEnv = "NOTEBOOK_BASH_KERNEL_CAPABILITIES"
Variables ¶
This section is empty.
Functions ¶
func EmbedImageSrc ¶
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 ¶
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 ¶
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: " )