JupyterLab - Get JSON of current notebook

294 views
Skip to first unread message

Sterling Paramore

unread,
Jul 11, 2017, 6:31:39 PM7/11/17
to Project Jupyter
Is there a way to get the JSON representation of a notebook that is currently open that could be passed to nbformat?

I'm trying to create a pandas dataframe from a markdown cell with a table in it.  This is kind of a hack workaround for having some way of easily editing and pretty-printing dataframes within a notebook.

Thanks,
Sterling

Brian Granger

unread,
Jul 11, 2017, 6:35:24 PM7/11/17
to Project Jupyter
In the file browser of JupyterLab, right click on the file and "Open
With" the "Editor"
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/9d0f6ae5-0e9a-4500-acba-51ead21f032c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgra...@calpoly.edu and elli...@gmail.com

Sterling Paramore

unread,
Jul 11, 2017, 6:52:46 PM7/11/17
to jup...@googlegroups.com
Thanks Brian,

I guess I wasn't clear enough.  I want to be able to execute code within a cell that gets the JSON for the current notebook.  Here's the best I can do currently.  It almost works, but I don't know how to get the name of the current notebook:

```
import nbformat

fp = open('TheNameOfThisWorkbook.ipynb')
nb = nbformat.read(fp, 4)

for cell in nb['cells']:
    print('---')
    print(cell)
```


On Tue, Jul 11, 2017 at 3:34 PM, Brian Granger <elli...@gmail.com> wrote:
In the file browser of JupyterLab, right click on the file and "Open
With" the "Editor"

On Tue, Jul 11, 2017 at 3:31 PM, Sterling Paramore <gnil...@gmail.com> wrote:
> Is there a way to get the JSON representation of a notebook that is
> currently open that could be passed to nbformat?
>
> I'm trying to create a pandas dataframe from a markdown cell with a table in
> it.  This is kind of a hack workaround for having some way of easily editing
> and pretty-printing dataframes within a notebook.
>
> Thanks,
> Sterling
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/9d0f6ae5-0e9a-4500-acba-51ead21f032c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgra...@calpoly.edu and elli...@gmail.com
--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Chris Colbert

unread,
Jul 11, 2017, 6:57:08 PM7/11/17
to Project Jupyter
As far as I know, the kernel doesn't know anything about the open notebook. The notebook file might not even be on the same machine as the kernel.

But, dataframes should already be display'able in a nice way in the notebook. Is there something missing from the default functionality?


On Tuesday, July 11, 2017 at 5:52:46 PM UTC-5, Sterling Paramore wrote:
Thanks Brian,

I guess I wasn't clear enough.  I want to be able to execute code within a cell that gets the JSON for the current notebook.  Here's the best I can do currently.  It almost works, but I don't know how to get the name of the current notebook:

```
import nbformat

fp = open('TheNameOfThisWorkbook.ipynb')
nb = nbformat.read(fp, 4)

for cell in nb['cells']:
    print('---')
    print(cell)
```

On Tue, Jul 11, 2017 at 3:34 PM, Brian Granger <elli...@gmail.com> wrote:
In the file browser of JupyterLab, right click on the file and "Open
With" the "Editor"

On Tue, Jul 11, 2017 at 3:31 PM, Sterling Paramore <gnil...@gmail.com> wrote:
> Is there a way to get the JSON representation of a notebook that is
> currently open that could be passed to nbformat?
>
> I'm trying to create a pandas dataframe from a markdown cell with a table in
> it.  This is kind of a hack workaround for having some way of easily editing
> and pretty-printing dataframes within a notebook.
>
> Thanks,
> Sterling
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/9d0f6ae5-0e9a-4500-acba-51ead21f032c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
bgra...@calpoly.edu and elli...@gmail.com

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Sterling Paramore

unread,
Jul 11, 2017, 7:21:54 PM7/11/17
to jup...@googlegroups.com
Yeah, I'd like the ability to edit dataframes directly in a nicely formatted table.  qGrid seemed to work well in Jupyter notebooks, but I fought for several hours trying to get it working in Lab to no avail. At pyData Seattle I recall hearing something about lack of support for some JavaScript output so I thought that might be the reason. 

Reply all
Reply to author
Forward
0 new messages