A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: add bokeh theme color to iframe background (#2128)
Myles Scolnickecd1fee16073
diff --git a/marimo/_output/formatters/bokeh_formatters.py b/marimo/_output/formatters/bokeh_formatters.pyindex ab6b9a1b9e..3b925b1766 100644--- a/marimo/_output/formatters/bokeh_formatters.py+++ b/marimo/_output/formatters/bokeh_formatters.py@@ -1,6 +1,8 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations+from typing import Optional+from marimo._messaging.mimetypes import KnownMimeTypefrom marimo._output.builder import hfrom marimo._output.formatters.formatter_factory import FormatterFactory@@ -32,6 +34,29 @@ class BokehFormatter(FormatterFactory):html_content = bokeh.embed.file_html(plot, bokeh.resources.CDN, theme=current_theme)++ # Try to get the background fill color+ background_fill_color: Optional[str] = None+ try:+ attrs = current_theme._json.get("attrs", {})+ background_fill_color = attrs.get("BaseColorBar", {}).get(+ "background_fill_color"+ ) or attrs.get("Plot", {}).get("background_fill_color")+ except Exception:+ pass++ # Maybe add <style> to the content+ if background_fill_color is not None:+ style_to_add = (+ "<style>"+ f"body{{background-color:{background_fill_color}}}"+ "</style>"+ )+ # Add above the </head> tag+ html_content = html_content.replace(+ "</head>", style_to_add + "</head>"+ )+return ("text/html",flatten_string(diff --git a/marimo/_smoke_tests/theming/bokeh_theme.py b/marimo/_smoke_tests/theming/bokeh_theme.pynew file mode 100644index 0000000000..1cfce1d4eb--- /dev/null+++ b/marimo/_smoke_tests/theming/bokeh_theme.py@@ -0,0 +1,63 @@+import marimo++__generated_with = "0.8.3"+app = marimo.App(width="medium")+++def __():+ from bokeh.plotting import figure, show+ from bokeh.io import curdoc+ return curdoc, figure, show+++def __(curdoc, figure):+ fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']+ counts = [5, 3, 4, 2, 4, 6]++ curdoc().theme = None++ p = figure(x_range=fruits, height=350, title="Fruit Counts",+ toolbar_location=None, tools="")++ p.vbar(x=fruits, top=counts, width=0.9)++ p.xgrid.grid_line_color = None+ p.y_range.start = 0+ p+ return counts, fruits, p+++def __(counts, curdoc, figure, fruits):+ curdoc().theme = "light_minimal"++ p3 = figure(x_range=fruits, height=350, title="Fruit Counts",+ toolbar_location=None, tools="")++ p3.vbar(x=fruits, top=counts, width=0.9)++ p3.xgrid.grid_line_color = None+ p3.y_range.start = 0+ p3+ return p3,+++def __(counts, curdoc, figure, fruits):+ curdoc().theme = "dark_minimal"++ p2 = figure(x_range=fruits, height=350, title="Fruit Counts",+ toolbar_location=None, tools="")++ p2.vbar(x=fruits, top=counts, width=0.9)++ p2.xgrid.grid_line_color = None+ p2.y_range.start = 0+ p2+ return p2,+++if __name__ == "__main__":+ app.run()