Skip to content
Snippets Groups Projects
Verified Commit 4c50e449 authored by David Beniamine's avatar David Beniamine
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
# Imported from seaborn tutorial https://nbviewer.jupyter.org/github/bokeh/bokeh-notebooks/blob/master/tutorial/06%20-%20Linking%20and%20Interactions.ipynb
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
x = [x*0.005 for x in range(0, 201)]
source = ColumnDataSource(data=dict(x=x, y=x))
plot = figure(plot_width=400, plot_height=400)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
slider = Slider(start=0.1, end=6, value=1, step=.1, title="power")
update_curve = CustomJS(args=dict(source=source, slider=slider), code="""
var data = source.data;
var f = slider.value;
x = data['x']
y = data['y']
for (i = 0; i < x.length; i++) {
y[i] = Math.pow(x[i], f)
}
// necessary becasue we mutated source.data in-place
source.change.emit();
""")
slider.js_on_change('value', update_curve)
show(column(slider, plot))
```
%% Output
%% Cell type:code id: tags:
``` python
#Imported from Interact_seaborn
from ipywidgets import interact, interactive
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
tips = sns.load_dataset("tips")
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
from bokeh.io import output_notebook, show
from bokeh.palettes import Category10_10 as palette
from bokeh.transform import factor_cmap
output_notebook()
@interact(color=["smoker","sex","day","time","size"])
def f(color):
cds_df = ColumnDataSource(tips)
p = figure(title="Tips repartition",
x_axis_label="Total bill",
y_axis_label="Tip")
categories=[str(x) for x in tips[color].unique()]
# Hack to fix bug with size being integer values
tips['size']=[str(x) for x in tips['size']]
colors = factor_cmap(color, palette=palette, factors=categories)
p.circle(x='total_bill', y='tip', color=colors, legend=colors, source=cds_df)
show(p)
```
%% Output
%% Cell type:code id: tags:
``` python
# Interactive plot with only matplotlib and jupyter interactive widget
from ipywidgets import interact, interactive
import matplotlib.pyplot as plt
import numpy as np
def ma_fonction(a,b,c):
plt.figure(2) # ???
x = np.linspace(-10,10, num=1000)
plt.plot(x, a*x**2+b*x+c)
plt.ylim(-10,10)
plt.show()
interactive_plot = interactive(ma_fonction, a=(-10,10), b=(-20,20), c=(-5,5))
interactive_plot
```
%% Output
%% Cell type:code id: tags:
``` python
# And again bokeh code
# Imported from seaborn tutorial https://nbviewer.jupyter.org/github/bokeh/bokeh-notebooks/blob/master/tutorial/06%20-%20Linking%20and%20Interactions.ipynb
from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
x = [x*0.005 for x in range(0, 201)]
source = ColumnDataSource(data=dict(x=x, y=x))
plot = figure(plot_width=400, plot_height=400)
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
slider = Slider(start=0.1, end=6, value=1, step=.1, title="power")
update_curve = CustomJS(args=dict(source=source, slider=slider), code="""
var data = source.data;
var f = slider.value;
x = data['x']
y = data['y']
for (i = 0; i < x.length; i++) {
y[i] = Math.pow(x[i], f)
}
// necessary becasue we mutated source.data in-place
source.change.emit();
""")
slider.js_on_change('value', update_curve)
show(column(slider, plot))
```
%% Output
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
import csv
lines = []
with open('test.csv') as csv_file:
dialect = csv.Sniffer().sniff(csv_file.read(1024))
csv_file.seek(0)
reader = csv.reader(csv_file, dialect)
for row in reader:
lines.append(row)
print(lines)
```
%% Output
[['nom', 'prenom', 'surnom'], ['toto', 'd', 'toto'], ['titi', 'a', 'tutu']]
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
# example dashboard
This repository is an example dashboard for the [django voila-stack](https://gitlab.tetras-libre.fr/tetras-libre/jupyter/voila-stack)
It works as follow
```
data/
mydata.py # Python script exposing three methods
# extractLastData() -> scraps the last data and return the downloaded file path
# Upload(path) -> upload data contained in path
# getDataSample() -> return a sample data for debugging pupose
dashboard/
myfirstdashboard.ipynb # Ipynotebook dashboard that will be rendered by voila
myfirstdashboard_housekeeping.py # Python script that generates data aggregates for myfirstdashbord
myseconddashboard.ipynb #Ipynotebook dashboard that will be rendered by voila
myseconddashboard_housekeeping.py # Python script that generates data aggregates for myseconddashbord
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment