4

I am trying to display my pandas dataframe in another "Output View" tab as shown in this iamge...

https://github.com/quantopian/qgrid/blob/master/docs/images/events_api.gif

I am able to install and try the basic features of qgrid using following commands. But not able to get the exact view as shown above.

!pip install qgrid
!jupyter nbextension enable --py --sys-prefix qgrid
!jupyter nbextension enable --py --sys-prefix  widgetsnbextension

import qgrid
import pandas as pd
df = pd.read_csv('some.csv')

qgrid_widget = qgrid.show_grid(df, show_toolbar=True)
qgrid_widget

qgrid_widget.get_changed_df()
shantanuo
  • 31,689
  • 78
  • 245
  • 403
  • 1
    Hi, Did you mean the view of the jupyter notebook in the tab, or something else. because your code is working perfectly and doing all same as in the gif. – Amit Gupta Apr 09 '19 at 04:50
  • I am not able to create a view of the jupyter notebook in the tab. You are correct @AmitGupta – shantanuo Apr 09 '19 at 06:42
  • Is a new browser window okay, or do you need it to specifically do it for a new tab? check this out https://stackoverflow.com/a/40855214/10953776, if you specifically need a new tab, most of it would be same, only a few commands would change and I don't want to plagarize his answer. – anand_v.singh Apr 09 '19 at 06:56
  • How do I get the "Create new view for output" option on right click as shown in the image? – shantanuo Apr 10 '19 at 05:14
  • Perhaps the main confusion here was jupyter v. jupyterlab. Jupyterlab has tabs; normal jupyter notebook does not. The image link you posted shows a jupyterlab window, but you say "jupyter notebook". – toddkaufmann Jan 11 '20 at 19:22

2 Answers2

7

These commands should work:

Pre-installation:

1. Assume you have conda environment called "myenv"
2. Assume you have jupyter-lab installed in that environment

Installation of New Conda environment

source activate myenv
pip install qgrid
jupyter labextension install qgrid
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter nbextension enable --py --sys-prefix qgrid
jupyter nbextension enable --py --sys-prefix widgetsnbextension

Load conda environment

source activate myenv
jupyter-lab
create a notebook under environment myenv

------------------- These are just pre installation procedures -------
------------------- Here is how you use qgrid in jupyter lab ----------

# Lets say you have a pandas dataframe `df`
qgrid_widget = qgrid.show_grid(df.head(), show_toolbar=True)
qgrid_widget
qgrid_widget.get_changed_df()

# right click on this cell
# click Create New View for Output # it will create new tab
# You will see the new window of dataframe

Confirmation

I just followed up the procedure for a new environment, and it works. enter image description here

BhishanPoudel
  • 15,974
  • 21
  • 108
  • 169
  • in your screen shot it is not possible to see the code to open the parallel window. would you be so kind to copy it in a comment? – JFerro Feb 18 '20 at 16:37
  • @Berlines The code in in the jupyterlab/jupyter-notebook can be anything. You just load a pandas dataframe using "qgrid", then, right click the on the jupyterlab then click on "Create New View for Output". All the steps are given in the answer. Hope that helps. – BhishanPoudel Feb 18 '20 at 22:29
3

Since this question has a bounty on it, I can't mark it as duplicate. To show the dataframe in another tab, you can use a little JavaScript. According to this post, here is a code that will show the dataframe in another tag:

from IPython.display import HTML
def View(df):
    css = """<style>
    table { border-collapse: collapse; border: 3px solid #eee; }
    table tr th:first-child { background-color: #eeeeee; color: #333; font-weight: bold }
    table thead th { background-color: #eee; color: #000; }
    tr, th, td { border: 1px solid #ccc; border-width: 1px 0 0 1px; border-collapse: collapse;
    padding: 3px; font-family: monospace; font-size: 10px }</style>
    """
    s  = '<script type="text/Javascript">'
    s += 'var win = window.open("", "Title", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=780, height=200, top="+(screen.height-400)+", left="+(screen.width-840));'
    s += 'win.document.body.innerHTML = \'' + (df.to_html() + css).replace("\n",'\\') + '\';'
    s += '</script>'
    return(HTML(s+css))

Then finally you can use the function to view a dataframe like this:

View(my_dataframe)

This should open the the dataframe in another tab.

xilpex
  • 3,097
  • 2
  • 14
  • 45