Skip to content

Commit

Permalink
fix: fallback to normal matplotlib when interactive is not supported (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mscolnick authored Dec 18, 2024
1 parent 77f6497 commit a463739
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions marimo/_plugins/stateless/mpl/_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional, Tuple, Union

from marimo import _loggers
from marimo._output.builder import h
from marimo._output.formatting import as_html
from marimo._output.hypertext import Html
Expand All @@ -29,8 +30,11 @@
)
from marimo._runtime.context.kernel_context import KernelRuntimeContext
from marimo._server.utils import find_free_port
from marimo._utils.platform import is_pyodide
from marimo._utils.signals import get_signals

LOGGER = _loggers.marimo_logger()

if TYPE_CHECKING:
from matplotlib.axes import Axes
from matplotlib.backends.backend_webagg_core import FigureManagerWebAgg
Expand Down Expand Up @@ -344,6 +348,14 @@ def interactive(figure: Union[Figure, SubFigure, Axes]) -> Html:
- An interactive matplotlib figure as an `Html` object
"""
# We can't support interactive plots in Pyodide
# since they require a WebSocket connection
if is_pyodide():
LOGGER.error(
"Interactive plots are not supported in Pyodide/WebAssembly"
)
return as_html(figure)

# No top-level imports of matplotlib, since it isn't a required
# dependency
from matplotlib.axes import Axes
Expand Down

0 comments on commit a463739

Please sign in to comment.