BT

InfoQ Homepage News .NET Interactive: Jupyter Notebooks with .NET Core - Preview 2

.NET Interactive: Jupyter Notebooks with .NET Core - Preview 2

This item in japanese

Bookmarks

.NET Interactive is the new name for Try .Net. This suite of APIs and command-line tools allows you to create interactive notebooks and documents combining rich text, code and data. One of the main use cases for .NET Interactive is embedding code into a Jupyter Notebook.

Jupyter Notebook with C# interactive code example

Preview 2 adds PowerShell to the list of languages supported along with C# and F#. Adding PowerShell opens notebooks up to a whole new set of people, system administrators. PowerShell is commonly used for automating administration tasks and runs on Linux, Windows, and macOS.

Although there have previously been some community contributed kernels such as Jaykul Jupyter-PowerShell and Vors jupyter-powershell, this new version can be used alongside other .NET languages in the same notebook. The initial preview is fairly basic but can run PowerShell code and display any of the PowerShell Output stream. There is work in place to add graphing capability via XPlot which is already supported by the C# and F# languages.

By having PowerShell in a notebook, an interactive report of system status, costs or security could be created. Alternatively a documented procedure for a complex change could include the actual steps to be run, for example automation of a certificate refresh. This "Literate DevOps" is demonstrated by Joel Bennett in the video below.

https://www.youtube.com/watch?v=XssVyyLV9tg
Literate DevOps with PowerShell and Jupyter - Joel Bennett

The .NET languages are added to Juypter via a module called a Jupyter Kernel.The Notebook Server is responsible for sending the code to the correct kernel which allows the .NET code to be parsed, compiled and run. The kernel then sends back a message containing the output which the server passes back to the client for display. Having the display and processing of code separate means that new languages can be independently added.

Notebook Server and message flows

Preview 2 also supports the Nteract SDK, allowing users to create their own REPL environment, enhance the Atom Editor with the Hydrogen plugin or create notebooks with the Nteract Desktop application. Nteract SDK is a toolkit of React components and JavaScript packages that can be used to make your own notebook clients or REPL.

Nteract Desktop Example with Powershell

Nteract Desktop is an Electron-based application running in Node.js. There are a few issues that arise between this preview and Nteract Desktop, for example the color coding of the PowerShell and C# code is not enabled, and some error messages were produced when testing. Note that other languages do color correctly.

You can also create .NET Interactive notebooks using JupyterLab, a web-based interactive development environment; the latest incarnation of Jupyter Notebooks. This open-source tool supports over 40 programming languages, markdown, HTML, images, videos, mathematical formulas, LaTeX, and custom MIME types.

You can share notebooks with others as a file, by hosting it on GitHub or using NBViewer.

In the notebook editor, you add cells containing code or markup languages. When the notebook runs, these are rendered and results are displayed.

To plot charts, the notebook user can use the built-in XPlot which renders the graphics using the JavaScript charting libraries Google Charts and Plotly.

Notebook with Chart

For more complex processing, you can include external dependencies in the form of NuGet packages, local assemblies or C# scripts. For example, the Reactive Extensions could be used to visualise a live stream of data from a system.

Notebook with external dependency and data stream in the form of an observable

.NET Interactive works with .NET Core 3.0 SDK or above, Nteract 0.22, Jupyter Notebook or JupyterLab 1.0 and runs on Linux, Windows, and macOS. .NET Interactive is installed as a global tool and hence one version is installed on your machine for all users.

Read the instructions on the GitHub repository to install .NET Interactive. Note that you should install the .Net Interactive tool using an administrator command prompt.

Alternatively, to try out .NET Interactive without installing anything locally, you can use Notebooks on Binder. This allows notebooks to be created from a web browser.

The same technology used in the .NET Notebooks also powers Microsoft’s .NET In-Browser tutorial and Focus Mode for their online books.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.