This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathdash-plotly-132-violin.py
78 lines (72 loc) · 2.28 KB
/
dash-plotly-132-violin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/iris.csv')
app = dash.Dash()
app.layout = html.Div(className='container', children=[
html.H1('Plotly.js Violin Plots in Dash'),
html.Hr(),
html.Div(className='two columns', children=[
dcc.RadioItems(
id='items',
options=[
{'label': 'Sepal Length', 'value': 'SepalLength'},
{'label': 'Sepal Width', 'value': 'SepalWidth'},
{'label': 'Petal Length', 'value': 'PetalLength'},
{'label': 'Petal Width', 'value': 'PetalWidth'}
],
value='SepalLength',
style={'display': 'block'}
),
html.Hr(),
dcc.RadioItems(
id='points',
options=[
{'label': 'Display All Points', 'value': 'all'},
{'label': 'Hide Points', 'value': False},
{'label': 'Display Outliers', 'value': 'outliers'},
{'label': 'Display Suspected Outliers', 'value': 'suspectedoutliers'},
],
value='all',
style={'display': 'block'}
),
html.Hr(),
html.Label('Jitter'),
dcc.Slider(
id='jitter',
min=0,
max=1,
step=0.1,
value=0.7,
updatemode='drag'
)
]),
html.Div(dcc.Graph(id='graph'), className='ten columns')
])
@app.callback(
Output('graph', 'figure'), [
Input('items', 'value'),
Input('points', 'value'),
Input('jitter', 'value')])
def update_graph(value, points, jitter):
return {
'data': [
{
'type': 'violin',
'x': df['Name'],
'y': df[value],
'text': ['Sample {}'.format(i) for i in range(len(df))],
'points': points,
'jitter': jitter
}
],
'layout': {
'margin': {'l': 30, 'r': 10, 'b': 30, 't': 0}
}
}
app.css.append_css({
'external_url': 'https://codepen.io/chriddyp/pen/dZVMbK.css'})
if __name__ == '__main__':
app.run_server(debug=True)