Coder Social home page Coder Social logo

bokeh-python-visualization's Introduction

Bokeh-Python-Visualization

A Bokeh project developed for learning and teaching Bokeh interactive plotting!

See my medium blog posts about making bokeh apps.

Requirements:

  • Python 3.6 (may work on other versions but has not been tested)
  • bokeh 0.12.16 (bokeh is a work in progress so subsequents update may break functionality. I will try to update as I can.)

The main application is located in the bokeh_app folder. To run the application, open a command prompt, change to the directory containing bokeh_app and run bokeh serve --show bokeh_app/. This runs a bokeh server locally and will automatically open the interactive dashboard in your browser at localhost:5006.

Any comments, suggestions, improvements are greatly appreciated!

bokeh-python-visualization's People

Contributors

willkoehrsen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bokeh-python-visualization's Issues

Install Manual / App not starting

Hi Will,
I saw your post on medium and just wanted to take a quick look, before diving deeper. :)
So I cloned your project and installed missing dependencies, but it is not starting? A requirements file would be nice too.

Mabye you have an idea why it is not starting.
Tried with python 3.65 (latest) on Win10 to start via "bokeh_app\main.py".

It looks like it starts and then gives me back the command prompt without any error message. I normally don't use python, so maybe I'm the issue. ;-)

KR,

Peter

AttributeError: 'str' object has no attribute 'append' using Python 3.5.3 and bokeh 0.12.16

I had to comment out these 2 lines in scripts/draw_map.py

hover_line.renderers.append(lines_glyph)
hover_circle.renderers.append(circles_glyph)

otherwise I would receive the following error and a blank page in the browser.

2018-05-24 16:59:06,237 Starting Bokeh server version 0.12.16 (running on Tornado 5.0.2)
2018-05-24 16:59:06,243 Bokeh app running at: http://localhost:5006/bokeh_app
2018-05-24 16:59:06,243 Starting Bokeh server with process id: 18459
[18471:18493:0524/165906.877041:ERROR:browser_gpu_channel_host_factory.cc(119)] Failed to launch GPU process.
Created new window in existing browser session.
/home/foo/.virtualenvs/BokehDashbord-8BNqqEK8/lib/python3.5/site-packages/pandas/core/frame.py:6201: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default.

To accept the future behavior, pass 'sort=True'.

To retain the current behavior and silence the warning, pass sort=False

sort=sort)
2018-05-24 16:59:10,798 Error running application handler <bokeh.application.handlers.directory.DirectoryHandler object at 0x7fe98e428fd0>: 'str' object has no attribute 'append'
File "draw_map.py", line 142, in make_plot:
hover_circle.renderers.append(circles_glyph) Traceback (most recent call last):
File "/home/foo/.virtualenvs/BokehDashbord-8BNqqEK8/lib/python3.5/site-packages/bokeh/application/handlers/code_runner.py", line 163, in run
exec(self._code, module.dict)
File "/home/foo/code/BokehDashbord/bokeh_app/main.py", line 34, in
tab4 = map_tab(map_data, states)
File "/home/foo/code/BokehDashbord/bokeh_app/scripts/draw_map.py", line 208, in map_tab
p = make_plot(src, xs, ys)
File "/home/foo/code/BokehDashbord/bokeh_app/scripts/draw_map.py", line 142, in make_plot
hover_circle.renderers.append(circles_glyph)
AttributeError: 'str' object has no attribute 'append'

CheckboxGroup active list not updating

Hi,

I'm trying to replicate the second in your series of tutorials but am having trouble with the CheckboxGroup part. While the initial carriers load and appear, there seems to be a disconnect that's preventing the CheckboxGroup active list from updating data displayed in the histogram. So when I check or uncheck a box, it won't be reflected in the histogram.

I've removed the binwidth and range sliders to cut down on the problem. Otherwise the code below is essentially as the original in your github.

def` histogram_bokeh(flights):
    
    def make_dataset(carrier_list, range_start = -60, range_end = 120, bin_width=5):
    
        #check to make sure start is less than end:
        assert range_start < range_end, "Start must be less than end!"

        by_carrier = pd.DataFrame(columns=['proportion', 'left', 'right',
                                          'f_proportion', 'f_interval',
                                          'name', 'color'])
        range_extent = range_end - range_start

        for i, carrier_name in enumerate(carrier_list):

            #subset to the carrier
            subset = flights[flights['name'] == carrier_name]

            # Create a histogram
            arr_hist, edges = np.histogram(subset['arr_delay'],
                                          bins = int(range_extent / bin_width),
                                          range = [range_start, range_end])

            # Divide the counts by the total to get a proportion and create df
            arr_df = pd.DataFrame({'proportion': arr_hist / np.sum(arr_hist),
                                  'left': edges[:-1],
                                  'right': edges [1:]})

            #Format the proportion
            arr_df['f_proportion'] = ['%0.5f' % proportion for proportion in arr_df['proportion']]

            #Format the interval
            arr_df['f_interval'] = ['%d to %d minutes' % (left, right) for left,
                                    right in zip(arr_df['left'], arr_df['right'])]
            #Assign the carrier for labels
            arr_df['name'] = carrier_name
            #Colour each carrier differently
            arr_df['color'] = Category20_16[i]
            #Add to the overall dataframe
            by_carrier = by_carrier.append(arr_df)
        
        # Overall dataframe
        by_carrier = by_carrier.sort_values(['name','left'])
        
        #Convert dataframe to column data source
        return ColumnDataSource(by_carrier)
        
    def make_plot(src):
        # Blank plot with correct labels
        p = figure(plot_width = 700, plot_height = 700,
                  title = "Histogram of Arrival Delays by Carrier",
                  x_axis_label = 'Delay (min)', y_axis_label = 'Proportion')

        # Quad glyphs to create a histogram
        p.quad(source = src, bottom = 0, top = 'proportion', left = 'left', right = 'right',
              color = 'color', fill_alpha = 0.7, hover_fill_color = 'color', legend = 'name',
              hover_fill_alpha = 1.0, line_color = 'black')

        # HoverTool
        hover = HoverTool(tooltips=[('Carrier', '@name'),
                                   ('Delay', '@f_interval'),
                                   ('Proportion', '@f_proportion')])
        p.add_tools(hover)
        return p
    
    
    def update(attr, old, new):
        carriers_to_plot = [carrier_selection.labels[i] for i in carrier_selection.active]
        new_src = make_dataset(carriers_to_plot)
        src.data.update(new_src.data)    
    
    carrier_selection = CheckboxGroup(labels = available_carriers, active=[0,1,9])
    carrier_selection.on_change('active', update)
    
    initial_carriers = [carrier_selection.labels[i] for i in carrier_selection.active]
    src = make_dataset(initial_carriers)
    
    p = make_plot(src)
        
    controls = WidgetBox(carrier_selection)
    
    # Create a row layout
    layout = row(controls, p)
    
    # make a tab with the layout
    tab = Panel(title = "histogram", child = layout) 
    tabs = Tabs(tabs=[tab]) #add tab2 to list for additional tabs
    
    return tabs

show(histogram_bokeh(flights))

Note that I found I need Panels in the last section to make it work. Otherwise, essentially the same. I suspect there might be something in the update function that's causing it to not work?

I am using bokeh 0.12.16.

Thanks!

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.