Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 46d8419

Browse files
committed
syncing things up
1 parent 8aff634 commit 46d8419

File tree

51 files changed

+1833
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1833
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
vv
22
*.pyc
33
cache/
4+
cache-directory/
45
.ropeproject

app_layout_function.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def serve_layout():
1414
html.Div(id='output-1'),
1515
html.Div(id='output-2'),
1616
dcc.Dropdown(
17-
id='input',
18-
options=[{'label': i, 'value': i} for i in ['a', 'b']]
19-
)
17+
id='input', options=[{
18+
'label': i,
19+
'value': i
20+
} for i in ['a', 'b']])
2021
])
2122

2223

dash-a-target-blank-external-link.gif

244 KB
Loading

dash-a-target-blank-external-link.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import dash
2+
import dash_html_components as html
3+
4+
app = dash.Dash()
5+
6+
app.layout = html.Div([
7+
html.A("Link to external site", href='https://plot.ly', target="_blank")
8+
])
9+
10+
if __name__ == '__main__':
11+
app.run_server(debug=True)

dash-cache-signal-session.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import dash
2+
from dash.dependencies import Input, Output
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import datetime
6+
from flask_caching import Cache
7+
import pandas as pd
8+
import time
9+
import uuid
10+
11+
app = dash.Dash()
12+
cache = Cache(app.server, config={
13+
'CACHE_TYPE': 'filesystem',
14+
'CACHE_DIR': 'cache-directory',
15+
'CACHE_THRESHOLD': 50 # should be equal to maximum number of active users
16+
})
17+
18+
@cache.memoize()
19+
def query_data(session_id):
20+
df = pd.DataFrame({'a': [datetime.datetime.now()]})
21+
return df.to_json()
22+
23+
24+
def dataframe(session_id):
25+
return pd.read_json(query_data(session_id))
26+
27+
def serve_layout():
28+
session_id = str(uuid.uuid4())
29+
df = dataframe(session_id)
30+
return html.Div([
31+
html.Div(session_id, id='session-id', style={'display': 'none'}),
32+
dcc.Dropdown(id='dropdown', value='a', options=[
33+
{'label': i, 'value': i} for i in ['a', 'b', 'c', 'd']
34+
]),
35+
html.Pre(id='output')
36+
])
37+
38+
app.layout = serve_layout
39+
40+
41+
@app.callback(Output('output', 'children'),
42+
[Input('dropdown', 'value'),
43+
Input('session-id', 'children')])
44+
def display_value(value, session_id):
45+
df = dataframe(session_id)
46+
return df.to_csv()
47+
48+
49+
if __name__ == '__main__':
50+
app.run_server(debug=True)

dash-datatable-custom-css.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import dash
2+
from dash.dependencies import Input, Output, State
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import dash_table_experiments as dt
6+
from flask import send_from_directory
7+
import json
8+
import pandas as pd
9+
import numpy as np
10+
import os
11+
import plotly
12+
13+
app = dash.Dash()
14+
server = app.server
15+
16+
app.scripts.config.serve_locally = True
17+
app.css.config.serve_locally = True
18+
19+
ROWS = [
20+
{'a': 'AA', 'b': 1},
21+
{'a': 'AB', 'b': 2},
22+
{'a': 'BB', 'b': 3},
23+
{'a': 'BC', 'b': 4},
24+
{'a': 'CC', 'b': 5},
25+
{'a': 'CD', 'b': 6}
26+
]
27+
28+
29+
app.layout = html.Div([
30+
html.Link(rel='stylesheet', href='/static/dash-datatable.css'),
31+
32+
dt.DataTable(
33+
rows=ROWS,
34+
35+
row_selectable=True,
36+
filterable=True,
37+
sortable=True,
38+
selected_row_indices=[],
39+
id='datatable'
40+
),
41+
html.Div(id='selected-indexes'),
42+
dcc.Graph(
43+
id='graph-gapminder'
44+
),
45+
], className="container")
46+
47+
48+
@app.server.route('/static/<path:path>')
49+
def static_file(path):
50+
static_folder = os.path.join(os.getcwd(), 'static')
51+
return send_from_directory(static_folder, path)
52+
53+
54+
if __name__ == '__main__':
55+
app.run_server(debug=True)

dash-datatable-editable-toggle.gif

62.4 KB
Loading

dash-datatable-editable-toggle.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import dash
2+
from dash.dependencies import Input, Output
3+
import dash_html_components as html
4+
import dash_core_components as dcc
5+
import dash_table_experiments as dt
6+
7+
app = dash.Dash()
8+
app.layout = html.Div([
9+
dcc.RadioItems(
10+
id='toggle-editable',
11+
options=[
12+
{'label': 'Editable', 'value': True},
13+
{'label': 'Non-Editable', 'value': False},
14+
],
15+
value=True
16+
),
17+
dt.DataTable(
18+
id='datatable',
19+
rows=[{'x': 1, 'y': 3}, {'x': 5, 'y': 1}],
20+
)
21+
])
22+
23+
@app.callback(
24+
Output('datatable', 'editable'),
25+
[Input('toggle-editable', 'value')])
26+
def update_editable(value):
27+
return value
28+
29+
30+
if __name__ == '__main__':
31+
app.run_server(debug=True)
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import dash
2+
from dash.dependencies import Input, Output, State
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import dash_table_experiments as dt
6+
from flask import send_from_directory
7+
import json
8+
import pandas as pd
9+
import numpy as np
10+
import os
11+
import plotly
12+
13+
app = dash.Dash()
14+
server = app.server
15+
16+
app.scripts.config.serve_locally = True
17+
app.css.config.serve_locally = True
18+
19+
ROWS = [
20+
{'a': 'AA', 'b': 1},
21+
{'a': 'AB', 'b': 2},
22+
{'a': 'BB', 'b': 3},
23+
{'a': 'BC', 'b': 4},
24+
{'a': 'CC', 'b': 5},
25+
{'a': 'CD', 'b': 6}
26+
]
27+
28+
29+
app.layout = html.Div([
30+
html.Link(rel='stylesheet', href='/static/dash-datatable-light-dark.css'),
31+
32+
html.Div(
33+
dt.DataTable(rows=ROWS),
34+
className='dark-table'
35+
),
36+
37+
html.Div(
38+
dt.DataTable(rows=ROWS),
39+
className='light-table'
40+
)
41+
])
42+
43+
44+
@app.server.route('/static/<path:path>')
45+
def static_file(path):
46+
static_folder = os.path.join(os.getcwd(), 'static')
47+
return send_from_directory(static_folder, path)
48+
49+
50+
if __name__ == '__main__':
51+
app.run_server(debug=True)

dash-datatable-resizable-columns.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import dash
2+
from dash.dependencies import Input, Output, State
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import dash_table_experiments as dt
6+
import json
7+
import pandas as pd
8+
import numpy as np
9+
import plotly
10+
11+
app = dash.Dash()
12+
server = app.server
13+
14+
app.scripts.config.serve_locally = True
15+
app.css.config.serve_locally = True
16+
17+
ROWS = [
18+
{'a': 'AA', 'b': 1},
19+
{'a': 'AB', 'b': 2},
20+
{'a': 'BB', 'b': 3},
21+
{'a': 'BC', 'b': 4},
22+
{'a': 'CC', 'b': 5},
23+
{'a': 'CD', 'b': 6}
24+
]
25+
26+
27+
app.layout = html.Div([
28+
dt.DataTable(
29+
rows=ROWS,
30+
column_widths=[50, 50],
31+
enable_drag_and_drop=True,
32+
row_selectable=True,
33+
filterable=True,
34+
sortable=True,
35+
selected_row_indices=[],
36+
id='datatable'
37+
),
38+
html.Div(id='selected-indexes'),
39+
], className="container")
40+
41+
42+
app.css.append_css({
43+
"external_url": "https://codepen.io/chriddyp/pen/bWLwgP.css"
44+
})
45+
46+
if __name__ == '__main__':
47+
app.run_server(debug=True)

dash-download-file-link-server.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import dash
2+
from dash.dependencies import Input, Output
3+
import dash_core_components as dcc
4+
import dash_html_components as html
5+
import flask
6+
import os
7+
import pandas as pd
8+
9+
10+
app = dash.Dash()
11+
12+
app.layout = html.Div([
13+
html.A(id='download-link', children='Download File'),
14+
dcc.Dropdown(
15+
id='dropdown',
16+
options=[{'label': i, 'value': i} for i in ['NYC', 'LA' 'SF']],
17+
value='NYC',
18+
clearable=False
19+
)
20+
])
21+
22+
@app.callback(Output('download-link', 'href'),
23+
[Input('dropdown', 'value')])
24+
def update_href(dropdown_value):
25+
df = pd.DataFrame({dropdown_value: [1, 2, 3]})
26+
relative_filename = os.path.join(
27+
'downloads',
28+
'{}-download.xlsx'.format(dropdown_value)
29+
)
30+
absolute_filename = os.path.join(os.getcwd(), relative_filename)
31+
writer = pd.ExcelWriter(absolute_filename)
32+
df.to_excel(writer, 'Sheet1')
33+
writer.save()
34+
return '/{}'.format(relative_filename)
35+
36+
37+
@app.server.route('/downloads/<path:path>')
38+
def serve_static(path):
39+
root_dir = os.getcwd()
40+
return flask.send_from_directory(
41+
os.path.join(root_dir, 'downloads'), path
42+
)
43+
44+
if __name__ == '__main__':
45+
app.run_server(debug=True)

dash-dropdown-multi.gif

72.4 KB
Loading

dash-dropdown-multi.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import dash
2+
from dash.dependencies import Input, Output
3+
import dash_html_components as html
4+
import dash_core_components as dcc
5+
6+
app = dash.Dash()
7+
8+
app.layout = html.Div([
9+
dcc.Dropdown(
10+
value=['a'],
11+
options=[{'label': i, 'value': i} for i in ['a', 'b', 'c', 'd']],
12+
multi=True,
13+
id='dropdown'
14+
),
15+
html.H3(id='output')
16+
])
17+
18+
@app.callback(Output('output', 'children'), [Input('dropdown', 'value')])
19+
def display_output(value):
20+
return str(value)
21+
22+
if __name__ == '__main__':
23+
app.run_server(debug=True)
169 KB
Loading

0 commit comments

Comments
 (0)