Package: qgridnext
Documentation|Demos|Presentation|ChangelogQgrid is a Jupyter widget that utilizesSlickGridto render pandas DataFrames within JupyterLab/Notebook. This allows you to explore your DataFrames with intuitive scrolling, sorting, and filtering controls, as well as edit your DataFrames by double clicking cells. Initially developed by Quantopian,its repoceased maintenance in 2020. QgridNext aims to continue maintaining and improving it for future Jupyter versions.CompatibilityQgridNext is compatible with recent versions of Jupyter:QgridNextJupyterLabNotebookVoilav2.0.0v3 - v4v5 - v7v0.2 - v0.5The test environments are provided in thetest_envsfolder. You can try the widget in these environments easily.QgridNext V2.0.0The first release v2.0.0 significantly improves compatibility and addresses bugs found in Qgrid v1.3.1.Support JupyterLab 4;Released as a prebuilt extension (now can be installed with one step);UI improvements:Fix infinitely expanding width of the container in voila <= 0.3;Prevent unexpected scrolling when clicking rows in Chrome for JupyterLab;Adapt canvas size when the sidebar width changes in JupyterLab;Fix poorly displayed left/right button of date picker;Correct text color in dark mode;Standardize HTML tags to fix poorly displayed filters;Building bug fixes:Fix inconsistent pkg name for embeddable qgrid bundle;Fix data_files finding that results in incomplete extension setup;Fix building errors for Node >= 18;Other fixes:EnsureDefaults.grid_optiondict instance are not shared across widget instances;Remove full-screen mode for voila compatibility;Remove deprecated QGridWidget alias, only QgridWidget is allowed;Replace deprecated usages for traitlets, pandas and jquery.InstallationInstalling with pip:pipinstallqgridnextRequirementsQgridNext supports Python 3.7+ and depends on the following packages:pandas>= 0.20ipywidgets>= 7numpytraitletsUsageExploring DataframesRendering your DataFrame:fromqgridimportshow_gridshow_grid(your_df)Qgrid excels in handling large DataFrames. For example, it can render a DataFrame with 10,000,000 rows in about 0.8 seconds:Column-specific options:Qgrid has the ability to set a number of options on a per column basis. This allows you to do things like explicitly specify which column should be sortable, editable, etc. For example, if you wanted to prevent editing on all columns except for a column named 'A', you could do the following:col_opts={'editable':False}col_defs={'A':{'editable':True}}show_grid(df,column_options=col_opts,column_definitions=col_defs)Row-specific options:Currently, Qgrid supports disabling row editing on a per-row basis, enabling row editability based on specific criteria:defcan_edit_row(row):returnrow['status']=='active'show_grid(df,row_edit_callback=can_edit_row)Updating an existing Qgrid widget: You can update an existing Qgrid widget's state using APIs likeedit_cell,change_selection,toggle_editable, andchange_grid_option.Event handlersUseonandoffmethods to attach/detach event handlers. They're available on both theqgridmodule (seeqgrid.on) and individualQgridWidgetinstances (seeqgrid.QgridWidget.on).Example:defhandle_json_updated(event,qgrid_widget):# Exclude 'viewport_changed' events since that doesn't change the DataFrameif(event['triggered_by']!='viewport_changed'):print(qgrid_widget.get_changed_df())# qgrid_widget = show_grid(...)qgrid_widget.on('json_updated',handle_json_updated)Alternatively, the traditionalobservemethod is available but not recommended due to its less granular event control:defhandle_df_change(change):print(change['new'])qgrid_widget.observe(handle_df_change,names=['_df'])Event handlers enable interesting integrations with other widgets/visualizations, like using qgrid to filter a DataFrame also displayed by another visualization.For more examples, see theevents notebook.TroubleshootIf you are not seeing the widget, check if the extension is installed and enabled:jupyterlabextensionlist
jupyterlabextensionenableqgridnext# enable it if disabledTestingMultiple test environments are provided intest_envs. You can perform automated tests by pytest, or manually test it in your browser.DevelopmentNote: JupyterLab 4 and NodeJS are required to build the extension package. You can usedev.ymlintest_envsfor a quick setup.gitclonehttps://github.com/zhihanyue/qgridnextcdqgridnext
pipinstall-ve.# Install package in development modepip install -ve .installs the package into your python environment as a symlink. It also creates symlinks of built JS extensions for your Jupyter environments automatically (implemented by our custom command insetup.py). After making any changes to the JS code, just rebuild it by:npm--prefix./jsinstallWhen uninstalling it, you need to clean up the JS symlinks via scriptunlink_dev.py:pipuninstallqgridnext
python./unlink_dev.pyContributingAll contributions, bug reports, bug fixes, documentation improvements, enhancements, demo improvements and ideas are welcome.