Code Monkey home page Code Monkey logo

bokeh-django's Introduction

Bokeh logo -- text is white in dark theme and black in light theme

Bokeh is an interactive visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics and affords high-performance interactivity across large or streaming datasets. Bokeh can help anyone who wants to create interactive plots, dashboards, and data applications quickly and easily.

Package Latest package version Supported Python versions Bokeh license (BSD 3-clause)
Project Github contributors Link to NumFOCUS Link to documentation
Downloads PyPI downloads per month Conda downloads per month NPM downloads per month
Build Current Bokeh-CI github actions build status Current BokehJS-CI github actions build status Codecov coverage percentage
Community Community support on discourse.bokeh.org Bokeh-tagged questions on Stack Overflow

Consider making a donation if you enjoy using Bokeh and want to support its development.

4x9 image grid of Bokeh plots

Installation

To install Bokeh and its required dependencies using pip, enter the following command at a Bash or Windows command prompt:

pip install bokeh

To install conda, enter the following command at a Bash or Windows command prompt:

conda install bokeh

Refer to the installation documentation for more details.

Resources

Once Bokeh is installed, check out the first steps guides.

Visit the full documentation site to view the User's Guide or launch the Bokeh tutorial to learn about Bokeh in live Jupyter Notebooks.

Community support is available on the Project Discourse.

If you would like to contribute to Bokeh, please review the Contributor Guide and request an invitation to the Bokeh Dev Slack workspace.

Note: Everyone who engages in the Bokeh project's discussion forums, codebases, and issue trackers is expected to follow the Code of Conduct.

Support

Fiscal Support

The Bokeh project is grateful for individual contributions, as well as for monetary support from the organizations and companies listed below:

NumFocus Logo CZI Logo Blackstone Logo
TideLift Logo Anaconda Logo NVidia Logo Rapids Logo

If your company uses Bokeh and is able to sponsor the project, please contact [email protected]

Bokeh is a Sponsored Project of NumFOCUS, a 501(c)(3) nonprofit charity in the United States. NumFOCUS provides Bokeh with fiscal, legal, and administrative support to help ensure the health and sustainability of the project. Visit numfocus.org for more information.

Donations to Bokeh are managed by NumFOCUS. For donors in the United States, your gift is tax-deductible to the extent provided by law. As with any donation, you should consult with your tax adviser about your particular tax situation.

In-kind Support

Non-monetary support can help with development, collaboration, infrastructure, security, and vulnerability management. The Bokeh project is grateful to the following companies for their donation of services:

bokeh-django's People

Contributors

philippjfr avatar sdc50 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

bokeh-django's Issues

Django Integration: Documentation and URL handling

Created from discussion around this discourse topic.

The main feature I am interested in is properly using autoload from bokeh.server.django to access a bokeh app without mangling the url in the request function. To demonstrate this, consider the django project named project and just using views/urls within said project directory (this could easily be extended to be contained within an app). Currently the following has to be done in order to support the generic 'title':

# in urls.py within the project directory
bokeh_apps = [
    autoload("home/x", views.app_handler),
]

urlpatterns = [
    path('admin/', admin.site.urls),
    path("home/<str:title>", views.app),
]

# in views

def app(request: HttpRequest, title) -> HttpResponse:
    script = server_document(request.build_absolute_uri("/home/x"), arguments={"title": title}) # breaks the django url
    return render(request, "embed.html", dict(script=script))

def app_handler(doc: Document) -> None:
    df = sea_surface_temperature.copy()
    source = ColumnDataSource(data=df)
    plot = figure(x_axis_type="datetime", y_range=(0, 25), y_axis_label="Temperature (Celsius)",
                  title="Sea Surface Temperature at 43.18, -70.43")
    plot.line("time", "temperature", source=source)

    doc.add_root(column(slider, plot))
   # taken from examples and simplified

# and then in routing.py
bokeh_app_config = apps.get_app_config('bokeh.server.django')

application = ProtocolTypeRouter({
    'websocket': AuthMiddlewareStack(URLRouter(bokeh_app_config.routes.get_websocket_urlpatterns())),
    'http': AuthMiddlewareStack(URLRouter(bokeh_app_config.routes.get_http_urlpatterns())),
})

Ideally, you could indicate to autoload that it will take a parameter and it would make that parameter available to that handler. Note that it is already technically available to the handler under doc.session_context.arguments, however I still had to explicitly put "/home/x"

A few issues from this example:

  1. In order to set this up you explicitly define the url that bokeh will set up it's WSConsumer and AutoloadJSConsumer, in this case "home/x/ws" and "home/x/'autoloadjsurl'".
  2. It's largely a pain as far as I can tell to actually do anything with the WSConsumer, for instance you can technically inherit WSConsumer like so:
class Wrapper(WSConsumer):

def __init__(self, scope: Dict[str, Any]):
    super().__init__(scope)

async def connect(self):
    await super().connect()
    print("connecting") # add your own code wherever you want here, and just forward along bokeh information

async def disconnect(self, close_code):
    await super().disconnect(close_code)

async def receive(self, text_data):
    await super().receive(text_data)

and substitute it into django/routing.py in add_new_routing(...):
self._websocket_urlpatterns.append(url(urlpattern("/ws"), Wrapper, kwargs=kwargs))
3. Documentation is lacking all around here, for instance what is the difference/the use cases between DocConsumer (document()) and AutoloadJsConsumer (autoload)

If a full project directory is required I will happily provide, but I think that this is mainly a documentation issue - I am happy to contribute!

This is on bokeh version 1.4.0, I looked at the recent commit bokeh/bokeh#9536 but that seemed to have just added token support so what I have put here should be up to date, at least concerning what I am discussing here!

Safe way to pass arguments to handler and retrieve python callbacks

hi there,

finally I'm using Autoload and not panels.
I'm now wondering what's the safest way to pass arguments to the handler, let's say I want to view a different image from a django list.
Also I'd like to persit information from the python callback to the django model, like I'd like to store the position of selected points from the bokeh graph.
It's not an issue per say, and I tried a few things, but it's not really conclusive.
If you have some ideas that would be great,
Thanks!

Using Panel>=1.3.0 in django_bokeh package

Hi There,

I am using the bokeh-django package to display a panel.chat.ChatInterface on my website.

The chat using the following panel_handler

def app(doc: Document) -> None:
    chat_interface.server_doc(doc)'

And is added to the bokeh_app with an autoload

bokeh_apps = [
    autoload("chat/", Agents.app)
]

After using the setup instructions for the README I was finally able to display the ChatInterface.
For this, I did have to alter the following in the setting.py

from bokeh.settings import settings as bokeh_settings
# bokeh_settings.resources = 'server'
bokeh_settings.resources = 'inline'

If I use the the resources setting as server, it does not seem to find the static files from Panel.

HTTP GET /chat/autoload.js?bokeh-autoload-element=p1002&bokeh-app-path=/chat&bokeh-absolute-url=http://127.0.0.1:8000/chat 200 [0.22, 127.0.0.1:52925]
HTTP GET /static/js/bokeh.min.js?v=53f9ca7a5b60daf7940a6e91ff6bdf0913c7a7c780cae58750c958d90d0cf4a638713847f81637ff880a0d2dad5c57cf9988ac65af54c12df96cd7c3dffb4ac3 304 [0.01, 127.0.0.1:52925]
HTTP GET /static/js/bokeh-gl.min.js?v=32bcb6e6ccbd3c1a02be8407ea0e1e0b05a12a8c47a196f065fcf8639d99113cd4fcf3a6939fce0478f9c12f2cb7763011318f4fb8b4b8b579132ea29de9a099 304 [0.01, 127.0.0.1:52931]
HTTP GET /static/js/bokeh-widgets.min.js?v=f90def549d46f97ac5d3451c79f33a81b406a43529102059db32abc76aa700f18b8009e5e096f6f7b222a3b51226e53e77e62f5e48ac82cb3de0b300c5100959 304 [0.01, 127.0.0.1:52932]
HTTP GET /static/extensions/panel/panel.min.js?v=59296d23d623ce0adf7675d22156e83b1248c8508135a65dd8a9e38c497e94a8 404 [0.03, 127.0.0.1:52933]
HTTP GET /static/js/bokeh-tables.min.js?v=b3381341845a3f3b239aa9204f891355ff51670b2bba887db6b5f1de2ad890c65ed1d3f4e9d60c389f78f3109f299ade900cb1148e6d718a953fb372820c8573 304 [0.03, 127.0.0.1:52934]

However when using the inline as setting it does load the chat panel, but I am getting the error that protocol is not a key in the _RequestProxy object. Is this due to changing the bokeh_settings?

ERROR:bokeh.application.application:Error running application handler <bokeh.application.handlers.function.FunctionHandler object at 0x00000276821FD490>: 'protocol'
File 'consumers.py', line 355, in __getattr__:
return self[key] Traceback (most recent call last):
  File "C:\dev\PromoAgent\venv\Lib\site-packages\bokeh\application\handlers\function.py", line 140, in modify_document    
    self._func(doc)
  File "C:\dev\PromoAgent\app\PromoAgent\pn_app.py", line 9, in app
    chat_interface.server_doc(doc)
  File "C:\dev\PromoAgent\venv\Lib\site-packages\panel\viewable.py", line 1038, in server_doc
    self._add_location(doc, location, model)
  File "C:\dev\PromoAgent\venv\Lib\site-packages\panel\viewable.py", line 329, in _add_location
    loc = state.location
          ^^^^^^^^^^^^^^
  File "C:\dev\PromoAgent\venv\Lib\site-packages\panel\io\state.py", line 996, in location
    loc = Location.from_request(self.curdoc.session_context.request)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\PromoAgent\venv\Lib\site-packages\panel\io\location.py", line 76, in from_request
    if request.protocol:
       ^^^^^^^^^^^^^^^^
  File "C:\dev\PromoAgent\venv\Lib\site-packages\bokeh\server\contexts.py", line 378, in __getattr__
    val = getattr(self._request, name, None)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\dev\PromoAgent\venv\Lib\site-packages\bokeh_django\consumers.py", line 355, in __getattr__
    return self[key]
           ~~~~^^^^^
KeyError: 'protocol'

Current dependencies are:
bokeh==3.2.0
bokeh-django==0.1.0
channels==3.0.5
daphne==3.0.2
Django==4.2.9
Jinja2==3.1.3
panel==1.3.0
tornado==6.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.