Skip to content

Commit

Permalink
working content table!
Browse files Browse the repository at this point in the history
  • Loading branch information
interrogator committed Dec 6, 2019
1 parent a195495 commit fe6d333
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
16 changes: 8 additions & 8 deletions explorer/parts/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ def _new_search(
Output("dialog-table", "displayed"),
Output("dialog-table", "message"),
Output("freq-table", "row_deletable"),
Output("download-link", "href"),
Output("session-tables", "data"),
Output("session-clicks-table", "data"),
],
Expand All @@ -293,6 +292,7 @@ def _new_search(
State("relative-for-table", "value"),
State("sort-for-table", "value"),
State("multiindex-switch", "on"),
State("content-table-switch", "on"),
State("chart-from-1", "options"),
State("chart-from-1", "value"),
State("session-configs", "data"),
Expand All @@ -314,6 +314,7 @@ def _new_table(
relkey,
sort,
multiindex_columns,
content_table,
table_from_options,
nv1,
conf,
Expand All @@ -328,7 +329,7 @@ def _new_table(
"""
# do nothing if not yet loaded
if n_clicks is None:
return [no_update] * 14
raise PreventUpdate

slug = url.rstrip("/").split("/")[-1]
conf = conf[slug]
Expand Down Expand Up @@ -387,13 +388,15 @@ def _new_table(
table = INITIAL_TABLES[slug]
else:
# generate table
table = corpus.table(
method = "table" if not content_table else "content_table"
table = getattr(corpus, method)(
show=show,
subcorpora=subcorpora,
relative=relative if relative != "corpus" else CORPORA[slug],
keyness=keyness,
sort=sort,
multiindex_columns=multiindex_columns
multiindex_columns=multiindex_columns,
show_frequencies=relative is not False and relative is not None
)
# round df if floats are used
if relative is not False or keyness:
Expand All @@ -412,9 +415,7 @@ def _new_table(
else:
max_row, max_col = conf["table_size"]
tab = table.iloc[:max_row, :max_col]
cols, data = _update_frequencies(tab, deletable=True)

csv_path = "todo"
cols, data = _update_frequencies(tab, True, content_table)

if not msg and not updating:
table_name = _make_table_name(this_table_list)
Expand All @@ -432,7 +433,6 @@ def _new_table(
bool(msg),
msg,
row_deletable,
csv_path,
session_tables,
session_click_table,
)
Expand Down
5 changes: 3 additions & 2 deletions explorer/parts/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,16 @@ def _get_cols(corpus, add_governor):
return [dict(value=v, label=l) for v, l in longs]


def _update_frequencies(df, deletable):
def _update_frequencies(df, deletable, content_table):
"""
Turn DF into dash table data for frequencies
"""
multicols = isinstance(df.columns, pd.MultiIndex)
names = ["_" + str(x) for x in df.index.names]
df.index.names = names
# col_order = list(df.index.names) + list(df.columns)
df = df.reset_index()
if not content_table:
df = df.reset_index()
if not multicols:
columns = [
{
Expand Down
19 changes: 17 additions & 2 deletions explorer/parts/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _build_frequencies_space(corpus, table, config):
sort_drop = html.Div(sort_drop, style=style.TSTYLE)
max_row, max_col = config["table_size"]
table = table.iloc[:max_row, :max_col]
columns, data = _update_frequencies(table, deletable=False)
columns, data = _update_frequencies(table, False, False)

# modify the style_index used for other tables to just work for this index
style_index = style.FILE_INDEX
Expand Down Expand Up @@ -247,10 +247,25 @@ def _build_frequencies_space(corpus, table, config):
],
style={**style.CELL_MIDDLE_35, **style.TSTYLE}
)
content = html.Span(
children=[
daq.BooleanSwitch(
theme={**DAQ_THEME, **{"primary": "#47d153"}},
id="content-table-switch",
on=False,
style={**style.MARGIN_5_MONO, **style.TSTYLE},
),
html.Div(
children="Show content, not frequency",
style={**style.MARGIN_5_MONO, **style.TSTYLE},
),
],
style={**style.CELL_MIDDLE_35, **style.TSTYLE}
)

gen = "Generate table"
generate = html.Button(gen, id="table-button", style=sty)
top = html.Div([show_check, subcorpora_drop, multi])
top = html.Div([show_check, subcorpora_drop, multi, content])
bottom = html.Div([sort_drop, relative_drop, generate])
toolbar = html.Div([top, bottom], style=style.VERTICAL_MARGINS)
div = html.Div([toolbar, freq_table])
Expand Down

0 comments on commit fe6d333

Please sign in to comment.