pygraphistry icon indicating copy to clipboard operation
pygraphistry copied to clipboard

Feature request: Auto-display for plottables in Jupyter notebooks

Open lmeyerov opened this issue 4 months ago • 0 comments

Feature Request

It would be great if PyGraphistry plottables that already have a dataset_id (i.e., have been uploaded/plotted) could automatically display themselves as an iframe when evaluated in a Jupyter notebook cell.

Current Behavior

Currently, even when a plottable has already been plotted and has a dataset_id, it doesn't auto-display:

import graphistry as g

# Plot and get back a plottable with dataset_id
plotter = g.nodes(df, 'node_id').edges(df2, 'src', 'dst').plot()

# Later in another cell, this doesn't display anything even though it has dataset_id
plotter  # Just shows object repr, not the visualization

Desired Behavior

When a plottable with an existing dataset_id is the last expression in a Jupyter cell, it should automatically render as an iframe:

# This should auto-display the iframe since it already has dataset_id
plotter  # Shows the interactive graph in an iframe

Implementation Suggestion

This could be implemented by adding _repr_html_() method to the Plottable class that:

  1. Checks if self._dataset_id exists
  2. If yes, returns an iframe HTML pointing to the visualization
  3. If no, returns the regular repr
def _repr_html_(self):
    if hasattr(self, '_dataset_id') and self._dataset_id:
        url = f"{self._server}/graph/graph.html?dataset={self._dataset_id}"
        return f'<iframe src="{url}" width="100%" height="600"></iframe>'
    return None  # Fall back to regular repr

Benefits

  • More intuitive notebook experience for already-plotted graphs
  • No unnecessary re-plotting/re-uploading
  • Consistent with other visualization libraries
  • Useful for sharing notebooks where graphs are pre-computed
  • Better for demos and teaching

Important Note

This is NOT about auto-plotting graphs that haven't been plotted yet. This is only for displaying already-plotted graphs that have a dataset_id.

lmeyerov avatar Aug 02 '25 19:08 lmeyerov