Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
recursive-include streamlit_bokeh/frontend/build *
include streamlit_bokeh/py.typed
prune streamlit_bokeh/frontend/node_modules
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ include = ["streamlit_bokeh*"]
exclude = ["e2e_playwright*", "scripts*", "build*", "dist*", "venv*", ".*"]

[tool.setuptools.package-data]
streamlit_bokeh = ["frontend/build/**/*", "pyproject.toml"]
streamlit_bokeh = ["frontend/build/**/*", "pyproject.toml", "py.typed"]
2 changes: 1 addition & 1 deletion scripts/check_license_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# Exclude files, because they make it obvious which product they relate to.
r"|(LICENSE|NOTICES|CODE_OF_CONDUCT\.md|README\.md)$"
# Exclude files, because they do not support comments
r"|\.(json|prettierrc|nvmrc)$"
r"|\.(json|prettierrc|nvmrc|typed)$"
# Exclude yarn.lock
r"|yarn\.lock$"
# Exclude .yarn folder
Expand Down
50 changes: 27 additions & 23 deletions streamlit_bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import importlib.metadata
import json
import os
from typing import TYPE_CHECKING
from collections.abc import Callable
from typing import TYPE_CHECKING, Any

import bokeh
import streamlit as st
from bokeh.embed import json_item
from packaging.version import Version

if TYPE_CHECKING:
from bokeh.plotting.figure import Figure
from bokeh.model import Model


# Create a _RELEASE constant. We'll set this to False while we're developing
Expand All @@ -47,17 +48,23 @@
)

# Version-gated component registration
_component_func: Callable[..., Any]

if _IS_USING_CCV2:
_component_kwargs: dict[str, object] = {
"name": "streamlit-bokeh.streamlit_bokeh",
"js": "v2/index-*.mjs",
"html": "<div class='stBokehContainer'></div>",
}
# Streamlit 1.53+ accepts isolate_styles in the `component(...)` call.
if _IS_USING_UPDATED_ISOLATE_STYLES_PARAM:
_component_kwargs["isolate_styles"] = _ISOLATE_STYLES

_component_func = st.components.v2.component(**_component_kwargs)
_component_func = st.components.v2.component(
name="streamlit-bokeh.streamlit_bokeh",
js="v2/index-*.mjs",
html="<div class='stBokehContainer'></div>",
isolate_styles=_ISOLATE_STYLES,
)
else:
_component_func = st.components.v2.component(
name="streamlit-bokeh.streamlit_bokeh",
js="v2/index-*.mjs",
html="<div class='stBokehContainer'></div>",
)
else:
if not _RELEASE:
_component_func = st.components.v1.declare_component(
Expand All @@ -77,7 +84,7 @@


def streamlit_bokeh(
figure: "Figure",
figure: "Model",
use_container_width: bool = True,
theme: str = "streamlit",
key: str | None = None,
Expand All @@ -86,8 +93,8 @@ def streamlit_bokeh(

Parameters
----------
figure: bokeh.plotting.figure.Figure
A Bokeh figure to plot.
figure: bokeh.model.Model
A Bokeh model, typically a figure, to plot.
use_container_width : bool
Whether to override the figure's native width with the width of
the parent container. If ``use_container_width`` is ``False``,
Expand Down Expand Up @@ -126,20 +133,17 @@ def streamlit_bokeh(

if _IS_USING_CCV2:
# Call through to our private component function.
_call_kwargs: dict[str, object] = {
"key": key,
"data": {
"figure": json.dumps(json_item(figure)),
"bokeh_theme": theme,
"use_container_width": use_container_width,
},
data = {
"figure": json.dumps(json_item(figure)),
"bokeh_theme": theme,
"use_container_width": use_container_width,
}
# Streamlit 1.51-1.52 accepts isolate_styles on the returned component
# function (it moved to `component(...)` in 1.53).
if not _IS_USING_UPDATED_ISOLATE_STYLES_PARAM:
_call_kwargs["isolate_styles"] = _ISOLATE_STYLES

_component_func(**_call_kwargs)
_component_func(key=key, data=data, isolate_styles=_ISOLATE_STYLES)
else:
_component_func(key=key, data=data)

return None
else:
Expand Down
1 change: 1 addition & 0 deletions streamlit_bokeh/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading