Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh and how to make it into a GUI

I am writing in python and have all my functionalities for analyzing datasets. Now, I would like to turn these functions into a user-ready application that, in a sense, works like an .exe app. In bokeh, I saw that you could create a plot, table...etc; however, is it possible to create a GUI where you can:

  1. upload a file for analysis
  2. load functions from my written python to analyze the uploaded file
  3. graph the results onto a graph
  4. click different buttons that can take you to different (so-called) pages so that you can perform different functions.

basically it can go from one page to the other kind of like a webpage where you click one button it links you to the next page for another purpose and home to go back. Could you potentially do this with bokeh?

like image 726
Jeff The Liu Avatar asked Sep 14 '25 14:09

Jeff The Liu


1 Answers

There are several examples of data web applications created using Bokeh at demo.bokeh.org. Here is one modeled after the "Shiny Movie Explorer", but written in pure Python/Bokeh (instead of R/Shiny).

enter image description here

You can find much more details about creating and deploying Bokeh applications in the Running a Bokeh Server chapter of the docs.

Here is a complete (but simpler) example that demonstrates the basic gist and structure:

import numpy as np

from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure

# Set up data
x = np.linspace(0, 4*np.pi, 200)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))

# Set up plot
plot = figure(title="my sine wave")
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)

# Set up widgets
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1)


# Set up callbacks
def update_data(attrname, old, new):

    # Get the current slider values and set new data
    k = freq.value
    x = np.linspace(0, 4*np.pi, 200)
    y = np.sin(k*x)
    source.data = dict(x=x, y=y)

freq.on_change('value', update_data)

# Set up layouts and add to document    
curdoc().add_root(column(freq, plot))
curdoc().title = "Sliders"

To run this locally you'd execute:

bokeh serve --show myscript.py

For more sophisticated deployments (i.e. with proxies) or to embed directly in e.g. Flask, see the docs.

like image 117
bigreddot Avatar answered Sep 17 '25 06:09

bigreddot