Skip to content
This repository has been archived by the owner on Nov 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from KyleKing/development
Browse files Browse the repository at this point in the history
refactor: run poetry doit and update
  • Loading branch information
KyleKing committed Dec 9, 2021
2 parents fb6c60d + 6d4c850 commit 26d8ccd
Show file tree
Hide file tree
Showing 44 changed files with 2,687 additions and 3,269 deletions.
1 change: 1 addition & 0 deletions .calcipy_packaging.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
15 changes: 10 additions & 5 deletions .dash_tutorials/02-dash-core-components.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,21 @@
figure=go.Figure(
data=[
go.Bar(
x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012],
x=[
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
],
y=[219, 99, 97, 112, 127, 180, 236, 207, 236, 263, 350, 430, 474, 526, 488, 537, 500, 439],
name='Rest of world',
marker=go.bar.Marker(
color='rgb(55, 83, 109)',
),
),
go.Bar(
x=[1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012],
x=[
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012,
],
y=[16, 13, 10, 11, 28, 37, 43, 55, 56, 88, 105, 156, 270, 299, 340, 403, 549, 499],
name='China',
marker=go.bar.Marker(
Expand Down Expand Up @@ -229,7 +233,8 @@
@app.callback(
dash.dependencies.Output('output-container-button', 'children'),
[dash.dependencies.Input('button', 'n_clicks')],
[dash.dependencies.State('input-box', 'value')])
[dash.dependencies.State('input-box', 'value')],
)
def update_output(n_clicks, value):
"""Indicate button-click event."""
return f'The input value was "{value}" and the button has been clicked {n_clicks} times' # noqa: DAR101, DAR201
Expand Down
82 changes: 54 additions & 28 deletions .dash_tutorials/08_px-charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,50 @@
# See explanation with: `print(px.data.iris.__doc__)`

# Possible argument combinations
px.scatter(iris, x='sepal_width', y='sepal_length', color='species', marginal_y='violin',
marginal_x='box', trendline='ols')
px.scatter(
iris, x='sepal_width', y='sepal_length', color='species', marginal_y='violin',
marginal_x='box', trendline='ols',
)
px.scatter(iris, x='sepal_width', y='sepal_length', color='species', marginal_y='rug', marginal_x='histogram')
px.scatter(tips, x='total_bill', y='tip', facet_row='time', facet_col='day', color='smoker', trendline='ols',
category_orders={'day': ['Thur', 'Fri', 'Sat', 'Sun'], 'time': ['Lunch', 'Dinner']})
px.scatter(
tips, x='total_bill', y='tip', facet_row='time', facet_col='day', color='smoker', trendline='ols',
category_orders={'day': ['Thur', 'Fri', 'Sat', 'Sun'], 'time': ['Lunch', 'Dinner']},
)

iris['e'] = iris['sepal_width'] / 100
px.scatter(iris, x='sepal_width', y='sepal_length', color='species', error_x='e', error_y='e')
del iris['e']

# Animations!
px.scatter(gapminder.query('year==2007'), x='gdpPercap', y='lifeExp', size='pop', color='continent',
hover_name='country', log_x=True, size_max=60)
px.scatter(gapminder, x='gdpPercap', y='lifeExp', animation_frame='year', animation_group='country',
size='pop', color='continent', hover_name='country', facet_col='continent',
log_x=True, size_max=45, range_x=[100, 100000], range_y=[25, 90])
px.scatter(
gapminder.query('year==2007'), x='gdpPercap', y='lifeExp', size='pop', color='continent',
hover_name='country', log_x=True, size_max=60,
)
px.scatter(
gapminder, x='gdpPercap', y='lifeExp', animation_frame='year', animation_group='country',
size='pop', color='continent', hover_name='country', facet_col='continent',
log_x=True, size_max=45, range_x=[100, 100000], range_y=[25, 90],
)

# Example of each chart type
px.scatter_matrix(iris, dimensions=['sepal_width', 'sepal_length', 'petal_width', 'petal_length'], color='species')

px.parallel_coordinates(
iris, color='species_id',
labels={'species_id': 'Species',
'sepal_width': 'Sepal Width', 'sepal_length': 'Sepal Length',
'petal_width': 'Petal Width', 'petal_length': 'Petal Length'},
labels={
'species_id': 'Species',
'sepal_width': 'Sepal Width', 'sepal_length': 'Sepal Length',
'petal_width': 'Petal Width', 'petal_length': 'Petal Length',
},
color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2,
)

px.parallel_categories(tips, color='size', color_continuous_scale=px.colors.sequential.Inferno)

px.line(gapminder, x='year', y='lifeExp', color='continent', line_group='country', hover_name='country',
line_shape='spline', render_mode='svg')
px.line(
gapminder, x='year', y='lifeExp', color='continent', line_group='country', hover_name='country',
line_shape='spline', render_mode='svg',
)

px.area(gapminder, x='year', y='pop', color='continent', line_group='country')

Expand All @@ -108,34 +120,48 @@
px.density_heatmap(iris, x='sepal_width', y='sepal_length', marginal_x='rug', marginal_y='histogram')

px.bar(tips, x='sex', y='total_bill', color='smoker', barmode='group')
px.bar(tips, x='sex', y='total_bill', color='smoker', barmode='group', facet_row='time', facet_col='day',
category_orders={'day': ['Thur', 'Fri', 'Sat', 'Sun'], 'time': ['Lunch', 'Dinner']})
px.bar(
tips, x='sex', y='total_bill', color='smoker', barmode='group', facet_row='time', facet_col='day',
category_orders={'day': ['Thur', 'Fri', 'Sat', 'Sun'], 'time': ['Lunch', 'Dinner']},
)

px.histogram(tips, x='total_bill', y='tip', color='sex', marginal='rug', hover_data=tips.columns)
px.histogram(tips, x='sex', y='tip', histfunc='avg', color='smoker', barmode='group',
facet_row='time', facet_col='day', category_orders={'day': ['Thur', 'Fri', 'Sat', 'Sun'],
'time': ['Lunch', 'Dinner']})
px.histogram(
tips, x='sex', y='tip', histfunc='avg', color='smoker', barmode='group',
facet_row='time', facet_col='day', category_orders={
'day': ['Thur', 'Fri', 'Sat', 'Sun'],
'time': ['Lunch', 'Dinner'],
},
)

px.strip(tips, x='total_bill', y='time', orientation='h', color='smoker')

px.box(tips, x='day', y='total_bill', color='smoker', notched=True)

px.violin(tips, y='tip', x='smoker', color='sex', box=True, points='all', hover_data=tips.columns)

px.scatter_ternary(election, a='Joly', b='Coderre', c='Bergeron', color='winner', size='total', hover_name='district',
size_max=15, color_discrete_map={'Joly': 'blue', 'Bergeron': 'green', 'Coderre': 'red'})
px.scatter_ternary(
election, a='Joly', b='Coderre', c='Bergeron', color='winner', size='total', hover_name='district',
size_max=15, color_discrete_map={'Joly': 'blue', 'Bergeron': 'green', 'Coderre': 'red'},
)

px.line_ternary(election, a='Joly', b='Coderre', c='Bergeron', color='winner', line_dash='winner')

px.scatter_polar(wind, r='value', theta='direction', color='strength', symbol='strength',
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1])
px.scatter_polar(
wind, r='value', theta='direction', color='strength', symbol='strength',
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1],
)

px.line_polar(wind, r='value', theta='direction', color='strength', line_close=True,
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1])
px.line_polar(
wind, r='value', theta='direction', color='strength', line_close=True,
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1],
)

px.bar_polar(wind, r='value', theta='direction', color='strength',
# template='plotly_dark',
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1])
px.bar_polar(
wind, r='value', theta='direction', color='strength',
# template='plotly_dark',
color_discrete_sequence=px.colors.sequential.Plotly[-2::-1],
)

# # Maps, need Mapbox token
# px.set_mapbox_access_token(open('.mapbox_token').read())
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -35,18 +35,18 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.15.3
rev: v2.20.0
hooks:
- id: commitizen
additional_dependencies: ['git+https://github.com/KyleKing/cz_legacy.git@bfff2ab4134c26a31f1e7f9c3a8d4bedba824b08']
stages: [commit-msg]
- repo: https://github.com/asottile/pyupgrade
rev: v2.10.0
rev: v2.29.1
hooks:
- id: pyupgrade
stages: [push]
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.1.0
rev: v2.2.1
hooks:
- id: add-trailing-comma
stages: [push]
Expand Down
64 changes: 36 additions & 28 deletions _try_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,46 @@
# Notice the column with "editor": "input" - these cells can be edited
# See tabulator editor for options http://tabulator.info/docs/4.8/edit
columns = [
{"title": "Name", "field": "name", "width": 150, "headerFilter": True, "editor": "input"},
{"title": "Age", "field": "age", "hozAlign": "left", "formatter": "progress"},
{"title": "Favourite Color", "field": "col", "headerFilter": True},
{"title": "Date Of Birth", "field": "dob", "hozAlign": "center"},
{"title": "Rating", "field": "rating", "hozAlign": "center", "formatter": "star"},
{"title": "Passed?", "field": "passed", "hozAlign": "center", "formatter": "tickCross"}
{'title': 'Name', 'field': 'name', 'width': 150, 'headerFilter': True, 'editor': 'input'},
{'title': 'Age', 'field': 'age', 'hozAlign': 'left', 'formatter': 'progress'},
{'title': 'Favourite Color', 'field': 'col', 'headerFilter': True},
{'title': 'Date Of Birth', 'field': 'dob', 'hozAlign': 'center'},
{'title': 'Rating', 'field': 'rating', 'hozAlign': 'center', 'formatter': 'star'},
{'title': 'Passed?', 'field': 'passed', 'hozAlign': 'center', 'formatter': 'tickCross'},
]

# Setup some data
data = [
{"id": 1, "name": "Oli Bob", "age": "12", "col": "red", "dob": ""},
{"id": 2, "name": "Mary May", "age": "1", "col": "blue", "dob": "14/05/1982"},
{"id": 3, "name": "Christine Lobowski", "age": "42", "col": "green", "dob": "22/05/1982"},
{"id": 4, "name": "Brendon Philips", "age": "125", "col": "orange", "dob": "01/08/1980"},
{"id": 5, "name": "Margret Marmajuke", "age": "16", "col": "yellow", "dob": "31/01/1999"},
{"id": 6, "name": "Fred Savage", "age": "16", "col": "yellow", "rating": "1", "dob": "31/01/1999"},
{"id": 6, "name": "Brie Larson", "age": "30", "col": "blue", "rating": "1", "dob": "31/01/1999"},
{'id': 1, 'name': 'Oli Bob', 'age': '12', 'col': 'red', 'dob': ''},
{'id': 2, 'name': 'Mary May', 'age': '1', 'col': 'blue', 'dob': '14/05/1982'},
{'id': 3, 'name': 'Christine Lobowski', 'age': '42', 'col': 'green', 'dob': '22/05/1982'},
{'id': 4, 'name': 'Brendon Philips', 'age': '125', 'col': 'orange', 'dob': '01/08/1980'},
{'id': 5, 'name': 'Margret Marmajuke', 'age': '16', 'col': 'yellow', 'dob': '31/01/1999'},
{'id': 6, 'name': 'Fred Savage', 'age': '16', 'col': 'yellow', 'rating': '1', 'dob': '31/01/1999'},
{'id': 6, 'name': 'Brie Larson', 'age': '30', 'col': 'blue', 'rating': '1', 'dob': '31/01/1999'},
]

# Additional options can be setup here
# these are passed directly to tabulator
# In this example we are enabling selection
# Allowing you to select only 1 row
# and grouping by the col (color) column
options = {"groupBy": "col", "selectable": 1}
options = {'groupBy': 'col', 'selectable': 1}

# downloadButtonType
# takes
# css => class names
# text => Text on the button
# type => type of download (csv/ xlsx / pdf, remember to include appropriate 3rd party js libraries)
# filename => filename prefix defaults to data, will download as filename.type
downloadButtonType = {"css": "btn btn-primary", "text": "Export", "type": "xlsx"}
downloadButtonType = {'css': 'btn btn-primary', 'text': 'Export', 'type': 'xlsx'}


# clearFilterButtonType
# takes
# css => class names
# text => Text on the button
clearFilterButtonType = {"css": "btn btn-outline-dark", "text": "Clear Filters"}
clearFilterButtonType = {'css': 'btn btn-outline-dark', 'text': 'Clear Filters'}

# Add a dash_tabulator table
# columns=columns,
Expand All @@ -87,23 +87,27 @@
# data=data,
options=options,
downloadButtonType=downloadButtonType,
clearFilterButtonType=clearFilterButtonType
clearFilterButtonType=clearFilterButtonType,
),
html.Div(id='output'),
dcc.Interval(
id='interval-component-iu',
interval=1 * 10, # in milliseconds
n_intervals=0,
max_intervals=0
)
max_intervals=0,
),

])


# dash_tabulator can be populated from a dash callback
@app.callback([Output('tabulator', 'columns'),
Output('tabulator', 'data')],
[Input('interval-component-iu', 'n_intervals')])
@app.callback(
[
Output('tabulator', 'columns'),
Output('tabulator', 'data'),
],
[Input('interval-component-iu', 'n_intervals')],
)
def initialize(val):
return columns, data

Expand All @@ -114,12 +118,16 @@ def initialize(val):
# dataFiltering => header filters as typed, before filtering has occurred (you get partial matching)
# dataFiltered => header filters and rows of data returned
# to receive a dict of the row values
@app.callback(Output('output', 'children'),
[Input('tabulator', 'rowClicked'),
Input('tabulator', 'cellEdited'),
Input('tabulator', 'dataChanged'),
Input('tabulator', 'dataFiltering'),
Input('tabulator', 'dataFiltered')])
@app.callback(
Output('output', 'children'),
[
Input('tabulator', 'rowClicked'),
Input('tabulator', 'cellEdited'),
Input('tabulator', 'dataChanged'),
Input('tabulator', 'dataFiltering'),
Input('tabulator', 'dataFiltered'),
],
)
def display_output(row, cell, dataChanged, filters, dataFiltered):
print(row)
print(cell)
Expand Down
38 changes: 22 additions & 16 deletions dash_charts/app_px.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class TabBase(AppBase):
takes_args: bool = True
"""If True, will pass arguments from UI to function."""

templates: list = ['ggplot2', 'seaborn', 'simple_white', 'plotly',
'plotly_white', 'plotly_dark', 'presentation', 'xgridoff',
'ygridoff', 'gridon', 'none']
templates: list = [
'ggplot2', 'seaborn', 'simple_white', 'plotly',
'plotly_white', 'plotly_dark', 'presentation', 'xgridoff',
'ygridoff', 'gridon', 'none',
]
"""List of templates from: `import plotly.io as pio; pio.templates`"""

# Must override in child class
Expand Down Expand Up @@ -150,19 +152,23 @@ def return_layout(self) -> dict:
"""
self.verify_types_for_layout()

return html.Div([ # noqa: ECE001
html.Div([
dropdown_group('Plot Type:', self._il[self.id_func], self.func_opts, value=self.func_opts[0]['label']),
dropdown_group('Template:', self._il[self.id_template], self.t_opts, value=self.t_opts[0]['label']),
] + [
dropdown_group(f'{dim}:', self._il[dim], self.col_opts, value=self.default_dim_name.get(dim, None))
for dim in self.dims
] + [
dropdown_group(f'{dim}:', self._il[dim], [opts_dd(item, item) for item in items])
for dim, items in self.dims_dict.items()
], style={'width': '25%', 'float': 'left'}),
min_graph(id=self._il[self.id_chart], style={'width': '75%', 'display': 'inline-block'}),
], style={'padding': '15px'})
return html.Div(
[ # noqa: ECE001
html.Div(
[
dropdown_group('Plot Type:', self._il[self.id_func], self.func_opts, value=self.func_opts[0]['label']),
dropdown_group('Template:', self._il[self.id_template], self.t_opts, value=self.t_opts[0]['label']),
] + [
dropdown_group(f'{dim}:', self._il[dim], self.col_opts, value=self.default_dim_name.get(dim, None))
for dim in self.dims
] + [
dropdown_group(f'{dim}:', self._il[dim], [opts_dd(item, item) for item in items])
for dim, items in self.dims_dict.items()
], style={'width': '25%', 'float': 'left'},
),
min_graph(id=self._il[self.id_chart], style={'width': '75%', 'display': 'inline-block'}),
], style={'padding': '15px'},
)

def create_callbacks(self) -> None:
"""Register callbacks necessary for this tab."""
Expand Down
10 changes: 6 additions & 4 deletions dash_charts/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def dropdown_group(name, _id, options, form_style=None, **dropdown_kwargs):
"""
if form_style is None:
form_style = {}
return dbc.FormGroup([
dbc.Label(name),
dcc.Dropdown(id=_id, options=options, **dropdown_kwargs),
], style=form_style)
return dbc.FormGroup(
[
dbc.Label(name),
dcc.Dropdown(id=_id, options=options, **dropdown_kwargs),
], style=form_style,
)


def format_email_pass_id(submit_id):
Expand Down
Loading

0 comments on commit 26d8ccd

Please sign in to comment.