interactive: .NET PowerShell notebook does not work with Plotly

Describe the bug

Trying to execute code within a .NET PowerShell notebook (locally using Jupyter lab, locally using VS Code and also online) does throw an error when trying to display Plotly charts via New-PlotlyChart. Example code: `$chart = [Graph.Bar]::new()

$chart.x = 20,14,23 $chart.y = ‘lions’, ‘tigers’, ‘bears’ $chart.orientation=‘h’

New-PlotlyChart -Trace $chart | Out-Display`

Error: InvalidOperation: Unable to find type [Graph.Bar]. The term ‘New-PlotlyChart’ is not recognized as a name of a cmdlet, function, script file

Please complete the following:

Which version of .NET Interactive are you using? There are a few ways to find this out: 1.0.216002+26986fc7149e69110f7485a7e02d5f8db166eebf

  • OS
    • [x ] Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • [x ] Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • [ x] Jupyter Lab
    • nteract
    • [ x] Visual Studio Code
    • Visual Studio Code Insiders
    • Other (please specify)

Screenshots

image image

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (13 by maintainers)

Most upvoted comments

I would not call then diversions, they are interesting takes and feature improvements! Thank you for the contributions to the project. I would love to see more work that makes extension and api even more tuned into the kernel language consuming it. That will make the user experience incredibly better.

On 16 Apr 2021, at 08:37, jhoneill @.***> wrote:

Just a nod that I’m fine with closing it. I think I’ve created two diversions which should be items in their own right. Sorry for that.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

@dfinke
Sorry fingers going faster than brain when I pasted. The whole thing is

#!pwsh
$pshome
$p = Get-process -id $pid   
$p, $p.Parent, $p.Parent.Parent,$p.Parent.Parent.parent,$p.Parent.Parent.parent.parent
Get-CimInstance -ClassName win32_process -Filter "processID = $($p.id)" |  select -expand commandline
Get-CimInstance -ClassName win32_process -Filter "processID = $($p.Parent.id)" |  select -expand commandline
Get-CimInstance -ClassName win32_process -Filter "processID = $($p.Parent.parent.id)" |  select -expand commandline
Get-CimInstance -ClassName win32_process -Filter "processID = $($p.Parent.parent.parent.id)" |  select -expand commandline
Get-CimInstance -ClassName win32_process -Filter "processID = $($p.Parent.parent.parent.parent.id)" |  select -expand commandline

The output is

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
    182   311.59     325.31       5.92   34192   1 dotnet-interactive
     21    11.54      23.05       0.39   13612   1 dotnet
     78    84.69      87.78       9.89   31108   1 Code - Insiders
     34   178.89     181.13      69.58   30032   1 Code - Insiders
     40    54.00      78.54      18.42   20188   1 Code - Insiders
"C:\Users\xxxxxx\.dotnet\tools\dotnet-interactive.exe" jupyter --default-kernel csharp C:\Users\xxx~1\AppData\Local\Temp\tmp-311089zVT7p0ij0My.json 
dotnet interactive jupyter --default-kernel csharp C:\Users\xxx~1\AppData\Local\Temp\tmp-311089zVT7p0ij0My.json
"C:\Users\xxxxxxx\AppData\Local\Programs\Microsoft VS Code Insiders\Code - Insiders.exe" --inspect-port=0   etc. et.c

Notice it’s gone back to --default-kernel csharp

@colombod image

Which gives me a clue If I change it to the last one This disappears image

The language on the cell is respected and the two command lines become

"C:\Program Files\dotnet\dotnet.exe" C:\Users\xxxxx\.nuget\packages\microsoft.dotnet-interactive\1.0.221202\tools/net5.0/any/Microsoft.DotNet.Interactive.App.dll [vscode] stdio --working-dir c:\Users\xxxx\Documents\AzDo\ --http-port 50111
dotnet tool run dotnet-interactive -- [vscode] stdio --working-dir c:\Users\xxxx\Documents\AzDo\ --http-port 50111

Every time I exit and restart vs code it reverts to the Jupyter version which would explain why I was getting the old version of .NET Interactive which was associated with the Jupyter Server and couldn’t get #!about show anything current.

If I start the server in anaconda and go to the browser I get these kernels image

Not quite the same set, and I get a third set in Az Data Studio.

Back at plotly It needs to be added manually and downloaded for each session ? Is that expected to remain ?

@jhoneill the dsl is pretty cool, would you mind have a look at the repo for XPlot and see if that could be embedded as part of the package extensions for poweshell support? Here is where we inject the powershell support

Btw if anyone wants a PowerShell module which wraps plotly with a nice DSL (well I think it’s nice) and a notebook with a stack of plotly examples in PowerShell (with and without the DSL) plotly.psm1 and plotly.ipynb from here https://github.com/jhoneill/Notebooks/tree/master/notebooks - there’s other junk in that repo, which people are free to help themselves to.

A VS code option, a Nuget block and 2 search and replace operations and this has gone from everything I had looking totally broken, to the most complicated thing I have working beautifully again. Thanks again to those who helped.

@colombod
I used dotnet nuget remove source powershell-daily, and hey-presto that now works 😃 Thanks.

Nuget each time is ugly, but until someone packages the plotly files in a different way it’s OK as a work around. I might look at that when I get the chance, but this was a rabbit hole I went down when a job someone is waiting for needed a notebook, and firing up notebooks on one machine led to one problem after another, there are way too many jobs on my stack to do that any time soon 😦

I still don’t know why the machine with anaconda and jupyter on it wants to default to the wrong kernel when VS-Code runs .Net Interactive Create New Blank Notebook @jonsequitur - should the code which creates a new notebook force the right Kernel ? Knowing to select it is OK but I can see it causing issues for other people.

Not sure but I think you have that path in some Nuget.Config. myget feeds are no longer supported and should be removed from your nuget sources. That is what is causing your code submission to fail.

Can you ensure your other machine doesn’t point to https://powershell.myget.org/F/powershell-core-daily/ ?

You are correct as the package needs to be reinstalled each session but after first success the package is in your local cache until a different version is loaded

On 14 Apr 2021, at 01:24, jhoneill @.***> wrote:

@colombod

It works on one machine for me on the other

Error: C:\Program Files\dotnet\sdk\5.0.104\NuGet.targets(131,5): error : Failed to retrieve information about ‘XPlot.Plotly.Interactive’ from remote source ‘https://powershell.myget.org/F/powershell-core-daily/FindPackagesById()?id=‘XPlot.Plotly.Interactive’&semVerLevel=2.0.0’. [C:\Users\mcp\AppData\Local\Temp\nuget\8804–277cd75b-df68-4928-9b27-b68d738cf5f7\Project.fsproj] C:\Program Files\dotnet\sdk\5.0.104\NuGet.targets(131,5): error : Response status code does not indicate success: 404 (Not Found). [C:\Users\mcp\AppData\Local\Temp\nuget\8804–277cd75b-df68-4928-9b27-b68d738cf5f7\Project.fsproj] It also needs to be reinstalled every session and re-added to paths.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.