A streamlit component for bi-directional communication with bokeh plots.

Overview

Streamlit Bokeh Events

A streamlit component for bi-directional communication with bokeh plots.

Its just a workaround till streamlit team releases support for bi-directional communication with plots.

Demo

Plots

demo

Widgets

Data Tables

demo2

Color Picker

demo3

Run Any Custom JS

demo4

Get data from Clipboard

demo5

Installation

pip install streamlit-bokeh-events

Usage

import streamlit as st
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CustomJS

# import function
from streamlit_bokeh_events import streamlit_bokeh_events

# create plot
p = figure(tools="lasso_select")
cds = ColumnDataSource(
    data={
        "x": [1, 2, 3, 4],
        "y": [4, 5, 6, 7],
    }
)
p.circle("x", "y", source=cds)

# define events
cds.selected.js_on_change(
    "indices",
    CustomJS(
        args=dict(source=cds),
        code="""
        document.dispatchEvent(
            new CustomEvent("YOUR_EVENT_NAME", {detail: {your_data: "goes-here"}})
        )
        """
    )
)

# result will be a dict of {event_name: event.detail}
# events by default is "", in case of more than one events pass it as a comma separated values
# event1,event2 
# debounce is in ms
# refresh_on_update should be set to False only if we dont want to update datasource at runtime
# override_height overrides the viewport height
result = streamlit_bokeh_events(
        bokeh_plot=p,
        events="YOUR_EVENT_NAME",
        key="foo",
        refresh_on_update=False,
        override_height=600,
        debounce_time=500)

# use the result
st.write(result)
Comments
  • Example error

    Example error

    Hi I'm receving this error:

    2021-09-02 16:00:51.015 ComponentRequestHandler: GET streamlit_bokeh_events.streamlit_bokeh_events/bootstrap.min.css.map read error Traceback (most recent call last):

    FileNotFoundError: [Errno 2] No such file or directory: 'c:\users\borg7803\anaconda3\envs\streamlit\lib\site-packages\streamlit_bokeh_events\frontend\build\bootstrap.min.css.map'

    opened by Borg93 4
  • Plot figure not retaining its state ( zoom and selected points )

    Plot figure not retaining its state ( zoom and selected points )

    Hi, This is my code:

    from bokeh.models import ColumnDataSource, CustomJS
    from bokeh.palettes import Category20
    from bokeh.plotting import figure
    from bokeh.transform import linear_cmap
    import numpy as np
    import pandas as pd
    import streamlit as st
    st.set_page_config(layout="wide")
    
    from streamlit_bokeh_events import streamlit_bokeh_events
    
    @st.cache
    def load_data():
        # ....
    
    df = load_data()
    
    st.title("Clustering")
    st.subheader("Umap Embedding")
    
    col1, col2 = st.beta_columns([2,1])
    
    with col1:
        p1 = figure(sizing_mode="stretch_both",
                    tools="pan,box_select,lasso_select,wheel_zoom,reset", 
                    active_drag="lasso_select",
                    active_scroll="wheel_zoom")
    
        cmap = linear_cmap("label", palette=Category20[20], low=df["label"].min(), high=df["label"].max())
        cds = ColumnDataSource(df)
        p1.circle("x", "y", source=cds, color=cmap, line_color=cmap)
    
        cds.selected.js_on_change("indices", CustomJS(args=dict(source=cds),
                code="""
                document.dispatchEvent(new CustomEvent("select_event", {detail: cb_obj.indices}))
                """
            )
        )
        event_result = streamlit_bokeh_events(p1, "select_event", key="select_event")
    
    with col2:
        if event_result is not None:
            st.dataframe(df.iloc[event_result["select_event"]])
    

    So I have a scatter plot on the left and a dataframe on the right. When I select a number of points in the scatter plot using the lasso tool, I want the dataframe on the right to update. This is working fine.

    However, when something was selected, all the not selected points should have a high alpha value, and should retain their high alpha value. This is not working. Apparently, the scatter plot is redrawn and even though the table shows the correct selection, all points in the plot have the same alpha value. I have also a screen capture of this behavior.

    streamlit-serve-2020-11-19-14-11-84

    Also, the zoom level and the whole plot resets (Not shown in the gif).

    Is there something I can do about that?

    Thank you, Flo

    opened by r0f1 4
  • Fix react scripts transpilation issue

    Fix react scripts transpilation issue

    Summary

    Transpilation of typescript code fails due to two issues stemming from react-scripts version 3.4.1.

    1. react-scripts=3.4.1's babel config does not support nullish coalescing operator (??).
    2. react-scripts=3.4.1's babel config does not support export namespace from semantics (i.e. export * as embed from "./embed";)

    Issue Description

    react-scripts's nullish coalescing operator issue is well described and recounted in create-react-app #9468. The gist is, the currently configured browserslist key in package.json fails because some browsers (<10%) do not support the nullish coalescing operator. See caniuse for the current breakdown. In short, the nullish coalescing operator (??) is supported by > 90% of browsers. ~2.5% of ~10% unsupported browsers are old versions of Chrome and Safari on IOS. I don't see this being a huge issue, but it might be worth mentioning in documentation (if the changes are accepted). However, others may disagree. If that is the case, using react-scripts eject is likely the only viable solution.

    create-react-app #9468's proposed solution is to change package.json's browserlist key from this,

    "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      },
    

    to this,

    "browserslist": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
    

    I've verified that this change removes the

    Failed to compile.
    
    ./node_modules/@bokeh/bokehjs/build/js/lib/models/expressions/stack.js 10:35
    Module parse failed: Unexpected token (10:35)
    File was processed with these loaders:
     * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.
    | 
    |   _v_compute(source) {
    >     const n = source.get_length() ?? 0;
    |     const result = new Float64Array(n);
    |
    

    transpilation error.

    However, after changing the browserlist key, an error related to export namespace semantics is raised. See below:

    Failed to compile.
    
    ./node_modules/@bokeh/bokehjs/build/js/lib/index.js 3:9
    Module parse failed: Unexpected token (3:9)
    File was processed with these loaders:
     * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
    You may need an additional loader to handle the result of these loaders.
    | export { version } from "./version";
    | export { index } from "./embed";
    > export * as embed from "./embed";
    | export * as protocol from "./protocol";
    | export * as _testing from "./testing";
    

    I tried bumping the react-scripts version to 3.4.4, but the error persisted. However, bumping react-scripts to 4.0.3 resolved the issue. Here are the create-react-app v4.X change logs. At a glance, I did not see anything referencing adding support for export namespace's, so I assume it is a product of a downstream babel plugin update.

    Recreate

    1. clone repo
    2. git checkout a67ca746960ab13e40cc660a8b53d6fa792c0582
    3. cd streamlit_bokeh_events/frontend/
    4. rm package-lock.json
    5. yarn
    6. yarn start

    Changes

    • browser target constraints lessened to avoid nullish coalescence issue. some browsers are no longer supported. see caniuse to see if you are affected.
    • react-scripts version bumped to 4.0.3.
    • package-lock.json removed and no longer tracked.
    opened by aaraney 2
  • Question: Clearing selection

    Question: Clearing selection

    Hey, I used normal ColumnDataSource, with columns

    I see your reply here: https://discuss.streamlit.io/t/make-streamlit-table-results-hyperlinks-or-add-radio-buttons-to-table/7883/2

    And wondered how can I clear the selection?

    result = streamlit_bokeh_events(bokeh_plot=p, events="INDEX_SELECT", key="foo", refresh_on_update=False, debounce_time=0)
    
    opened by ShaharMynd 2
  • Bump url-parse from 1.4.7 to 1.5.10 in /streamlit_bokeh_events/frontend

    Bump url-parse from 1.4.7 to 1.5.10 in /streamlit_bokeh_events/frontend

    Bumps url-parse from 1.4.7 to 1.5.10.

    Commits
    • 8cd4c6c 1.5.10
    • ce7a01f [fix] Improve handling of empty port
    • 0071490 [doc] Update JSDoc comment
    • a7044e3 [minor] Use more descriptive variable name
    • d547792 [security] Add credits for CVE-2022-0691
    • ad23357 1.5.9
    • 0e3fb54 [fix] Strip all control characters from the beginning of the URL
    • 61864a8 [security] Add credits for CVE-2022-0686
    • bb0104d 1.5.8
    • d5c6479 [fix] Handle the case where the port is specified but empty
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump url-parse from 1.4.7 to 1.5.7 in /streamlit_bokeh_events/frontend

    Bump url-parse from 1.4.7 to 1.5.7 in /streamlit_bokeh_events/frontend

    Bumps url-parse from 1.4.7 to 1.5.7.

    Commits
    • 8b3f5f2 1.5.7
    • ef45a13 [fix] Readd the empty userinfo to url.href (#226)
    • 88df234 [doc] Add soft deprecation notice
    • 78e9f2f [security] Fix nits
    • e6fa434 [security] Add credits for incorrect handling of userinfo vulnerability
    • 4c9fa23 1.5.6
    • 7b0b8a6 Merge pull request #223 from unshiftio/fix/at-sign-handling-in-userinfo
    • e4a5807 1.5.5
    • 193b44b [minor] Simplify whitespace regex
    • 319851b [fix] Remove CR, HT, and LF
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump follow-redirects from 1.12.1 to 1.14.8 in /streamlit_bokeh_events/frontend

    Bump follow-redirects from 1.12.1 to 1.14.8 in /streamlit_bokeh_events/frontend

    Bumps follow-redirects from 1.12.1 to 1.14.8.

    Commits
    • 3d81dc3 Release version 1.14.8 of the npm package.
    • 62e546a Drop confidential headers across schemes.
    • 2ede36d Release version 1.14.7 of the npm package.
    • 8b347cb Drop Cookie header across domains.
    • 6f5029a Release version 1.14.6 of the npm package.
    • af706be Ignore null headers.
    • d01ab7a Release version 1.14.5 of the npm package.
    • 40052ea Make compatible with Node 17.
    • 86f7572 Fix: clear internal timer on request abort to avoid leakage
    • 2e1eaf0 Keep Authorization header on subdomain redirects.
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump follow-redirects from 1.12.1 to 1.14.7 in /streamlit_bokeh_events/frontend

    Bump follow-redirects from 1.12.1 to 1.14.7 in /streamlit_bokeh_events/frontend

    Bumps follow-redirects from 1.12.1 to 1.14.7.

    Commits
    • 2ede36d Release version 1.14.7 of the npm package.
    • 8b347cb Drop Cookie header across domains.
    • 6f5029a Release version 1.14.6 of the npm package.
    • af706be Ignore null headers.
    • d01ab7a Release version 1.14.5 of the npm package.
    • 40052ea Make compatible with Node 17.
    • 86f7572 Fix: clear internal timer on request abort to avoid leakage
    • 2e1eaf0 Keep Authorization header on subdomain redirects.
    • 2ad9e82 Carry over Host header on relative redirects (#172)
    • 77e2a58 Release version 1.14.4 of the npm package.
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump path-parse from 1.0.6 to 1.0.7 in /streamlit_bokeh_events/frontend

    Bump path-parse from 1.0.6 to 1.0.7 in /streamlit_bokeh_events/frontend

    Bumps path-parse from 1.0.6 to 1.0.7.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump tmpl from 1.0.4 to 1.0.5 in /streamlit_bokeh_events/frontend

    Bump tmpl from 1.0.4 to 1.0.5 in /streamlit_bokeh_events/frontend

    Bumps tmpl from 1.0.4 to 1.0.5.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump ws from 5.2.2 to 5.2.3 in /streamlit_bokeh_events/frontend

    Bump ws from 5.2.2 to 5.2.3 in /streamlit_bokeh_events/frontend

    Bumps ws from 5.2.2 to 5.2.3.

    Release notes

    Sourced from ws's releases.

    5.2.3

    Bug fixes

    • Backported 00c425ec to the 5.x release line (76d47c14).
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • pip install streamlit-bokeh-events==0.1.3 not working

    pip install streamlit-bokeh-events==0.1.3 not working

    Hello! Couldn't install version 0.1.3 using pip - only 0.1.2. I'm using macOS Monterey 12.1 and Python 3.8.2 in venv pip install not working. I thing that is because there is no wheel file in the pypi repository for the new version Thank you in advance

    pip install streamlit-bokeh-events==0.1.3

    ERROR: Could not find a version that satisfies the requirement streamlit-bokeh-events==0.1.3 (from versions: 0.1.0, 0.1.1, 0.1.2) ERROR: No matching distribution found for streamlit-bokeh-events==0.1.3

    opened by achern108108 1
  • Not showing when using Spinner Widget in Bokeh

    Not showing when using Spinner Widget in Bokeh

    When I use Spinner Widget in Bokeh, nothing appear on streamlit-bokeh-events. On the other hand, st.bokeh_chart draw Bokeh graph properly. After I replaced Spinner to Slider, it worked on streamlit-bokeh-event. So, Spinner may do something bad. I tried some versions for streamlit, bokeh, and streamlit-bokeh-events, but not improved.

    opened by lozzy1 0
  • The lasso select in example widget_with_plot.py does not work

    The lasso select in example widget_with_plot.py does not work

    streamlit==1.3.0 streamlit-bokeh-events==0.1.2 bokeh==2.4.1

    When running the example widget_with_plot.py the scatter plot does not appear. It seems that a call to st.bokeh_chart(plot, use_container_width=False) is missing

    After adding this the plot appears but the lasso select event does not seem to trigger anything on the streamlit side. The selection on the table seems to work fine.

    Tried to install streamlit from git repo and get the following error StreamlitAPIException: No such component directory: '/home/mat/anaconda3/envs/koz_viewer/lib/python3.7/site-packages/streamlit_bokeh_events/frontend/build'

    I am guessing I am missing some build command?

    opened by msalvaris 0
  • Interaction with images

    Interaction with images

    Hi, I found your great package and am trying to use it also to interact with images. This does not seem to work immediately, or at least I didn't figure out how. The main point is the current functionality is based on a source = ColumnDataSource(df) which is not present if I am just plotting an image with p.image(image)

    What I would like to do is to tap on a point and/or select a region of the image and get out the coordinates for further processing.

    Is there an easy way of doing this? Thanks a lot!!!

    opened by tommasogiannantonio 1
  • CustomJS callback for select widgets to update bokeh scatter plot with streamlit_bokeh_events

    CustomJS callback for select widgets to update bokeh scatter plot with streamlit_bokeh_events

    Hi, I am new to bokeh applications with streamlit. I am trying to use customJS callback to update my plot if there is any change in the select widgets. I made up the following code and unfortunately plot is not updating after the change in select value. here is the minimal working example code:

    import pandas as pd
    import streamlit as st
    from copy import deepcopy
    import numpy as np
    from state import provide_state
    import bokeh
    from streamlit_bokeh_events import streamlit_bokeh_events
    from bokeh.layouts import column, row
    from bokeh.models import Slider, TextInput,Dropdown,Select,Button
    from bokeh.plotting import figure
    from bokeh.models import ColumnDataSource, CDSView, annotations, BooleanFilter, CustomJS, HoverTool
    from colorcet import glasbey
    
    def get_sizer(X, min_size, max_size):
        X_std = (X - X.min(axis=0)) / (X.max(axis=0) - X.min(axis=0))
        X_scaled = X_std * (max_size - min_size) + min_size
        return X_scaled.fillna(min_size)
    
    my_data = {  'group_1':['cat','dog','cat','dog','bull','bull','cat','rat'],
    'group_2':['lion','tiger','deer','tiger','deer','deer','lion','lion'],
    'group_3':['grass','bush','flower','leaf','grass','leaf','bush','grass'],
    'length':[5,6,5,6,4,3,7,3],
    'length_1':[25,36,45,36,54,43,76,37],
    'width':[1,2,4,3,4,2,4,5],
    'width_1':[11,12,14,13,14,12,14,15],
    'size_1': [10,23,45,12,10,45,43,29]
    }
    
    st.set_page_config(
        layout="wide",
        page_title="Reference Search",
    )
    st.write('''# Animal category search''')
    st.session_state.data = my_data.copy()
    plot_data = pd.DataFrame(st.session_state.data )
    
    coloring = Select(title="Select for coloring:", value="group_1", options=['group_1','group_2','group_3'])
    color_label = coloring.value
    sizing = Select(title="Select for sizing:", value="size_1", options=['length','length_1','width','width_1','size_1'])
    sizing_label = sizing.value
    
    palette = glasbey[:len(plot_data[color_label].unique())]
    color_map = bokeh.models.CategoricalColorMapper(factors=plot_data[color_label].unique(),palette=palette)
    plot_data['Size'] = get_sizer(plot_data[sizing_label], 10, 40)
    plot_data['Half_Size'] = plot_data['Size']/1000
    
    source = ColumnDataSource(plot_data.reset_index().rename(columns={'index':'Animal'}))
    print(source.data)
    p = figure( plot_width=800, plot_height=600,
        title = 'animal categories',
        tools='''pan,lasso_select,box_select,wheel_zoom,reset''',
        active_scroll = 'wheel_zoom',active_inspect = None,
        toolbar_location = 'above'
    )
    p.add_layout(annotations.Legend(), 'right')
    p.legend.click_policy = 'hide'
    
    p.scatter(x='length',y='width',
              color={'field': color_label, 'transform': color_map},
              legend=color_label, source=source)
    
    callback = CustomJS(args=dict(source=source,plot=p,coloring=coloring,sizing=sizing), code="""
        var data = source.data
        var a =coloring.value;
        var s = sizing.value;
        var palette = glasbey[:len(data[a].unique())];
        var color_map = bokeh.models.CategoricalColorMapper(factors=data[a].unique(),palette=palette)
        plot.color={'field': color_cat_label, 'transform': color_map}
        plot.legend=color_cat_label
        plot.change.emit()
        """)
    coloring.js_on_change('value', callback)
    sizing.js_on_change('value', callback)
    
    streamlit_bokeh_events(
        events="SelectEvent",
        bokeh_plot=column(row(coloring,sizing,width=800),p),
        key="foo2",
         #refresh_on_update=True,
        debounce_time=0,
    )
    

    It is able to produce a scatter plot with colourmap based on grouping initially, but not updating the plot once the grouping parameters for colourmap has changed through a select widget. initially let’s only concentrate on colouring widget, I am working on functionality to update my plot besed on select widgets colour group categories. To be precise, I am not able to write proper CustomJS callback to update my plot. when we only stick to coring widget change, there is no change in the source data x and y values. so, please do help me in writing proper CustomJS callback.

    opened by vinayreddy0911 0
  • Ability to set plot width

    Ability to set plot width

    I see that it's possible to override the plot height but I don't see an option for overriding the width. When using streamlit's wide layout (i.e. st.set_page_config(layout="wide")) the map width does not fill to fit the container width. The standard bokeh_chart has this ability (e.g. use_container_width=False, is it possible to add this?

    image

    opened by Castronova 1
Owner
Ashish Shukla
I (try to) code.
Ashish Shukla
Streamlit component for Let's-Plot visualization library

streamlit-letsplot This is a work-in-progress, providing a convenience function to plot charts from the Lets-Plot visualization library. Example usage

Randy Zwitch 9 Nov 3, 2022
🗾 Streamlit Component for rendering kepler.gl maps

streamlit-keplergl ?? Streamlit Component for rendering kepler.gl maps in a streamlit app. ?? Live Demo ?? Installation pip install streamlit-keplergl

Christoph Rieke 39 Dec 14, 2022
Bokeh Plotting Backend for Pandas and GeoPandas

Pandas-Bokeh provides a Bokeh plotting backend for Pandas, GeoPandas and Pyspark DataFrames, similar to the already existing Visualization feature of

Patrik Hlobil 822 Jan 7, 2023
Bokeh Plotting Backend for Pandas and GeoPandas

Pandas-Bokeh provides a Bokeh plotting backend for Pandas, GeoPandas and Pyspark DataFrames, similar to the already existing Visualization feature of

Patrik Hlobil 614 Feb 17, 2021
Personal IMDB Graphs with Bokeh

Personal IMDB Graphs with Bokeh Do you like watching movies and also rate all of them in IMDB? Would you like to look at your IMDB stats based on your

null 2 Dec 15, 2021
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 394 Dec 18, 2022
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 356 Feb 16, 2021
Painlessly create beautiful matplotlib plots.

Announcement Thank you to everyone who has used prettyplotlib and made it what it is today! Unfortunately, I no longer have the bandwidth to maintain

Olga Botvinnik 1.6k Jan 6, 2023
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 3, 2023
Easily convert matplotlib plots from Python into interactive Leaflet web maps.

mplleaflet mplleaflet is a Python library that converts a matplotlib plot into a webpage containing a pannable, zoomable Leaflet map. It can also embe

Jacob Wasserman 502 Dec 28, 2022
Python scripts to manage Chia plots and drive space, providing full reports. Also monitors the number of chia coins you have.

Chia Plot, Drive Manager & Coin Monitor (V0.5 - April 20th, 2021) Multi Server Chia Plot and Drive Management Solution Be sure to ⭐ my repo so you can

null 338 Nov 25, 2022
Plot, scatter plots and histograms in the terminal using braille dots

Plot, scatter plots and histograms in the terminal using braille dots, with (almost) no dependancies. Plot with color or make complex figures - similar to a very small sibling to matplotlib. Or use the canvas to plot dots and lines yourself.

Tammo Ippen 207 Dec 30, 2022
Example scripts for generating plots of Bohemian matrices

Bohemian Eigenvalue Plotting Examples This repository contains examples of generating plots of Bohemian eigenvalues. The examples in this repository a

Bohemian Matrices 5 Nov 12, 2022
This package creates clean and beautiful matplotlib plots that work on light and dark backgrounds

This package creates clean and beautiful matplotlib plots that work on light and dark backgrounds. Inspired by the work of Edward Tufte.

Nico Schlömer 205 Jan 7, 2023
Moscow DEG 2021 elections plots

Построение графиков на основе публичных данных о ДЭГ в Москве в 2021г. Описание Скрипты в данном репозитории позволяют собственноручно построить графи

null 9 Jul 15, 2022
This plugin plots the time you spent on a tag as a histogram.

This plugin plots the time you spent on a tag as a histogram.

Tom Dörr 7 Sep 9, 2022
A minimal Python package that produces slice plots through h5m DAGMC geometry files

A minimal Python package that produces slice plots through h5m DAGMC geometry files Installation pip install dagmc_geometry_slice_plotter Python API U

Fusion Energy 4 Dec 2, 2022
MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

Antonio López Rivera 162 Nov 11, 2022
Generate "Jupiter" plots for circular genomes

jupiter Generate "Jupiter" plots for circular genomes Description Python scripts to generate plots from ViennaRNA output. Written in "pidgin" python w

Robert Edgar 2 Nov 29, 2021