bokeh interactor and push_notebook doesn't refresh in VScode - python

I found a way to implement interactive slider using Bokeh without relying on Bokeh server, since Bokeh server doesn't work in VS code.
But this new way doesn't work in vs code either, though it still works in web browser.
Is it possible to run it in vs code?

The jupyter mentioned in your link is used, so please install the jupyter extension and create the .ipynb file.
I used the basic interactor demo in the link.
After all execution, I can get the content shown in the figure:
Of course, when you adjust the scroll bar below, you need to rerun the penultimate cell:

Related

Python code is not syntax highlighted in Pycharm notebook?

In the screenshot we see a pretty normal-ish python code cell within the Pycharm notebook viewer The viewer "understands" the notebook: it is bringing up the managed Jupyter server option and knows this is [python] code:
So then where did the syntax highlighting go to? How can it be [re-]enabled ?
#Wayne was headed the right direction: that link he provided Wrong Code Highlighting in Jupyter Notebooks had suggestion to reload the python interpreter.
Well in my case the interpreter is Synapse Pyspark and is grayed out since i'm presently running locally. I need to figure out how to change the interpreter: will update here at that point.
Update I needed to edit the json source of the ipynb file to find and remove the synapse kernel.

Python debugging and breakpoint

I usually use Matlab for processing results. However I'm required now to use Python. I want to set a breakpoint in a Python Jupyter notebook to go through functions. I was able to set up breakpoint but I can't actually go line by line debugging with this breakpoint. In Matlab I used to press F10 to do this.
In JupyterLab with the Xeus Python kernel (often tagged with 'XPython' when you are choosing the kernel) you can use the visual debugger. The run-next-line feature is the 'Next' button in the 'CALLSTACK' pane of the debugger panel. See the animation here for the 'Next' tooltip when hovering. And, although not featured in that animation, the tool tip actually shows 'Next (F10)' presently in my browser.
You can try it by clicking here. The session that spins up starts with a notebook open that has a nice introduction and guide to the features.
More can be found about the visual debugger here.
Current 'default' launches via MyBinder, have the Xeus Python kernel and the debugger available already. You can run the following code in a cell in any of those sessions to pull in the debugger demonstration notebook.
!curl -o debugger.ipynb https://raw.githubusercontent.com/jupyterlab/debugger/dfd6bf9d51a7a0cd78ca54f4173fcf527bd4d7fd/examples/index.ipynb
You'll find when you open it, that notebook also is set to trigger opening with the correct kernel necessary for debugging selected. Note that won't always be the first choice for when you start a new notebook.

How can I create and execute a cell in Jupyter Notebook server from a separate process (e.g., an editor, vim)?

I want to call an api on a running jupyter notebook to create or edit an existing cell, and to run it. When this is done, the browser page should also update, to show both the contents of the cell, and the output.
The intended use case for this api is a plugin for the vim editor that will take highlighted lines and execute them. The motivation for using jupyter notebook is that will allow visualization of plots and images using matplotlib, even though both vim and the notebook will be running on a remote server. The user would have a browser page open to the notebook, and separately a terminal open potentially that is ssh'ed to the machine and editing python code.
VSCode does exactly this in its python interactive mode, but I prefer to use the vim editor natively than switch to vscode simply to be able to do this.
There are several plugins being actively developed for this, and without having used them, it seems only vimpyter interacts with jupyter on the browser. Others like jupyter-vim and vim-ipython open the notebook inside a vim buffer.
If you can live without inline plots I find confortable having a neoterm terminal buffer where I can send lines to and from IPython.
You could use vscode's built in jupyter notebook support to convert the notebook into a python file
this is not an exact answer, but I've written a couple Jupyter plugins that may be helpful to you in this endeavor, JupyterGraffiti and JupyterTerminals. Graffiti has an API you can call to execute some of its functions, and it supports inline terminals you can control. JupyterTerminals provides only those inline terminals, but also has buttons you can add to control them. You could start and run vim inside these terminals. (If it's useful an API could be added to the JupyterTerminals plugin like Graffiti has.)

VSCode Jupyter: is there a way to make python interactive window work as default console?

I've recently switched to VSCode, and am wondering if there's a way to make the Python Interactive Window from the Jupyter support in VSCode work like the console in Spyder where I just have to select code and press ctrl+enter to send it, without having to create cells everytime.
For now I'm resigned to work with the Terminal until my code is clean and then create a cell when I have reusable code, and would like to just work directly with the PIW.
You can always change the default console setting by:
Opening the Command Palette (⇧⌘P)
Typing "Preferences:Open Settings (JSON)
Edit this line:
"python.dataScience.sendSelectionToInteractiveWindow": false
You should be able to do this with the latest python extension. The select the code you want to execute and press shift-enter. Is that not working?
For me (now) interactive mode runs after setting "jupyter.sendSelectionToInteractiveWindow": true
#FranciscoRZ. You should have seen a popup option for this, but if it didn't come up for you it can just be manually set in VSCode options. Just change this guy here:
Python->Data Science: Send Selection To Interactive Window
That should get you what you are looking for.
OP's Note: Accepting this answer because it will be the right anwser starting with the February release of VS Code Python
If you have the notebook saved as a python percentage script (which is more git friendly)
each "cell" will be delimited by # %% and the default run command is "Shift+Ctrl".
Later once you are working in the interactive window, If you want a particular cell you wrote on the fly to be in you script, there is one button which says "Paste code into file" right next to the recently executed cell in the interactive window.
And in case you are using the notebook for the sake of being able to later export it to html or pdf, once executed in the interactive window, there is an export button as well.

matplotlib plotting with python in xcode

I am trying to run python in XCode. The following simple plotting routine,
import matplotlib.pyplot as pyplot
pyplot.plot((0,1),(1,2))
pyplot.show()
returns no errors. XCode seems pretty happy with what it accomplishes when I hit the run button. But I get no plot window whatsoever, as far as I can tell. Is it hiding somewhere or what? How do I get to see it?
xcode will allow you to see plots if you move your code into an interactive notebook.
create a new file with the .ipynb file extension
copy your code into that file
You should be able not only to see the plots but also any other output your code is trying to send to the UI.

Categories

Resources