Skip to content

Instantly share code, notes, and snippets.

View dradecic's full-sized avatar

Dario Radečić dradecic

View GitHub Profile
@dradecic
dradecic / py-bokeh_1_imports.py
Last active August 25, 2019 10:39
Python-Bokeh - Gist 1: Imports
import math
import numpy as np
import pandas as pd
from bokeh.embed import components
from bokeh.models import ColumnDataSource, HoverTool, PrintfTickFormatter
from bokeh.plotting import figure
from bokeh.transform import factor_cmap
from flask import Flask, render_template, request
@dradecic
dradecic / py-bokeh_2_constants_and_helpers.py
Last active August 25, 2019 09:09
Python-Bokeh - Gist 2: Constants and Helper Functions
palette = ['#ba32a0', '#f85479', '#f8c260', '#00c2ba']
chart_font = 'Helvetica'
chart_title_font_size = '16pt'
chart_title_alignment = 'center'
axis_label_size = '14pt'
axis_ticks_size = '12pt'
default_padding = 30
chart_inner_left_padding = 0.015
chart_font_style_title = 'bold italic'
@dradecic
dradecic / py-bokeh_3_basic_flask.py
Created August 25, 2019 09:12
Python-Bokeh - Gist 3: Basic Flask Config
app = Flask(__name__)
@app.route('/')
def chart():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
@dradecic
dradecic / py-bokeh_4_base.html
Created August 25, 2019 09:13
Python-Bokeh - Gist 4: base.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="http://cdn.pydata.org/bokeh/release/bokeh-1.2.0.min.css" rel="stylesheet">
<link href="http://cdn.pydata.org/bokeh/release/bokeh-widgets-1.2.0.min.css" rel="stylesheet">
@dradecic
dradecic / py-bokeh_5_navbar.html
Created August 25, 2019 09:14
Python-Bokeh - Gist 5: navbar.html
<nav class="navbar navbar-expand-lg sticky-top navbar-dark" style="background-color: #ba32a0;">
<a class="navbar-brand title-text" href="#">Titanic - Dashboard</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav mr-auto">
</ul>
<form name="dropdown-form" action="" method="POST">
<select class="my-dropdown-menu" name="dropdown-select" style="padding:8px;border-radius:8px;">
@dradecic
dradecic / py-bokeh_6_index.html
Created August 25, 2019 09:15
Python-Bokeh Gist 6: index.html
{% extends 'base.html' %}
{% block content %}
{% include 'navbar.html' %}
<div class="container">
<div class="row mt-5">
<div class="col-6">
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Corporis provident ducimus incidunt dicta aliquam nesciunt quod laudantium tempore iusto ab veritatis, aperiam iste aspernatur quisquam consequuntur, accusamus ipsam magni perferendis ullam recusandae inventore? Cupiditate fugit recusandae reiciendis libero placeat esse saepe suscipit, sit eveniet ratione natus totam similique distinctio quas repudiandae ipsa excepturi sunt est nam molestias quibusdam dicta ab. Maiores provident reiciendis non porro ipsam vitae amet quas temporibus, molestiae odit laborum debitis voluptas quisquam esse ullam incidunt repellat ipsa quae sunt explicabo a? Perferendis, reprehenderit ab aspernatur id voluptatem explicabo cum reiciendis. Facere ipsam expedita, autem neque temporibus sequi impedit a ut nihil architecto! Numquam, excepturi a
@dradecic
dradecic / py-bokeh_7_main.css
Created August 25, 2019 09:15
Python-Bokeh Gist 7: main.css
.submit-btn {
padding:8px 16px;
border-radius:4px;
margin-left:8px;
background-color:#ba32a0;
border:2px solid #fff;
color:#fff;
font-weight:bold;
transition: 0.2s;
}
@dradecic
dradecic / py-bokeh_8_survived_bar_chart.py
Created August 25, 2019 09:18
Python-Bokeh Gist 8: Chart 1
def survived_bar_chart(dataset, pass_class, cpalette=palette[1:3]):
surv_data = dataset[dataset['Pclass'] == int(pass_class)]
surv_possibilities = list(surv_data['Survived'].value_counts().index)
surv_values = list(surv_data['Survived'].value_counts().values)
surv_possibilities_text = ['Did not Survive', 'Survived']
source = ColumnDataSource(data={
'possibilities': surv_possibilities,
'possibilities_txt': surv_possibilities_text,
'values': surv_values
@dradecic
dradecic / py-bokeh_9_class_titles_bar_chart.py
Created August 25, 2019 09:19
Python-Bokeh - Gist 9: Chart 2
def class_titles_bar_chart(dataset, pass_class, cpalette=palette):
ttl_data = dataset[dataset['Pclass'] == int(pass_class)]
title_possibilities = list(ttl_data['Title'].value_counts().index)
title_values = list(ttl_data['Title'].value_counts().values)
int_possibilities = np.arange(len(title_possibilities))
source = ColumnDataSource(data={
'titles': title_possibilities,
'titles_int': int_possibilities,
'values': title_values
@dradecic
dradecic / py-bokeh_10_age_hist.py
Created August 25, 2019 09:20
Python-Bokeh - Gist 10: Chart 3
def age_hist(dataset, pass_class, color=palette[1]):
hist, edges = np.histogram(dataset[dataset['Pclass'] == int(pass_class)]['Age'].fillna(df['Age'].mean()), bins=25)
source = ColumnDataSource({
'hist': hist,
'edges_left': edges[:-1],
'edges_right': edges[1:]
})
hover_tool = HoverTool(