Helper

This file contains helper functions that are used across multiple tabs

Functions

create_fig_from_diagram(diagram, id[, close_all])

Create html.Img from diagram

create_json_from_dict(d)

Create JSON from dictionary

dcc_loading(children[, dark_bg])

Get default dcc.Loading component

decode_df(df_ser)

De-serializes JSON format string to pandas DataFrame

decode_dict(d_ser)

De-serializes JSON format string to dictionary

encode_df(df)

Serializes pandas DataFrame to JSON format

encode_dict(d)

Serializes dictionary to JSON format

generate_datatable(df[, max_rows, dark])

Generate table from pandas DataFrame

get_excel_demo()

Create demo excel for Event Planner tab

get_excel_from_df(df)

Create excel from DataFrame

get_summary_statistics(df, cols[, dark])

Generate table of summary statistics for DataFrame for list of columns

get_worksheet(contents)

Get worksheet names from an excel file

parse_data(contents, filename[, worksheet])

Reads uploaded data into DataFrame

print_callback(print_function)

Decorator function to print callback on backend for debugging purposes

result_download_button(app, df[, dark])

Download button for processed data or results

result_download_text(input_text)

Download text for processed data or results

send_email(email_body[, subject, recipient])

Helper function to send email

table_css([dark])

Gets default dash_table CSS components

update_when_upload(contents, worksheet, …)

Reads uploaded data into DataFrame and return dash application objects

valid_email(email)

Helper function to validate email address

violin_plot()

Get data for plot, return plot

components.helper.create_fig_from_diagram(diagram, id, close_all=True)

Create html.Img from diagram

Parameters
  • diagram – input diagram

  • id (str) – id of html.Img object

  • close_all (bool) – whether to close image

Returns

(html.Img)

components.helper.create_json_from_dict(d)

Create JSON from dictionary

Parameters

d (dict) – input dictionary

Returns

(io.BytesIO)

components.helper.dcc_loading(children, dark_bg=True)

Get default dcc.Loading component

Parameters
  • children (list) – children of component

  • dark_bg (bool) – indicates whether loading icon is on dark background

Returns

(dcc.Loading)

components.helper.decode_df(df_ser)

De-serializes JSON format string to pandas DataFrame

Parameters

df_ser (str) – input serialized DataFrame

Returns

(pd.DataFrame)

components.helper.decode_dict(d_ser)

De-serializes JSON format string to dictionary

Parameters

d_ser (str) – input serialized dictionary

Returns

(dict)

components.helper.encode_df(df)

Serializes pandas DataFrame to JSON format

Parameters

df (pd.DataFrame) – input DataFrame

Returns

(str)

components.helper.encode_dict(d)

Serializes dictionary to JSON format

Parameters

d (dict) – input dictionary

Returns

(str)

components.helper.generate_datatable(df, max_rows=3, dark=True)

Generate table from pandas DataFrame

Parameters
  • df (pd.DataFrame) – input DataFrame

  • max_rows (int) – maximum number of rows to show

  • dark (bool) – if table is loaded in dark background, defaults to True

Returns

(dash_table.DataTable)

components.helper.get_excel_demo()

Create demo excel for Event Planner tab

Returns

(io.BytesIO)

components.helper.get_excel_from_df(df)

Create excel from DataFrame

Parameters

df (pd.DataFrame) – input DataFrame

Returns

(io.BytesIO)

components.helper.get_summary_statistics(df, cols, dark=True)

Generate table of summary statistics for DataFrame for list of columns

Parameters
  • df (pd.DataFrame) – input DataFrame

  • cols (list) – column(s) to get summary statistic for

  • dark (bool) – if table is loaded in dark background, defaults to True

Returns

(dash_table.DataTable)

components.helper.get_worksheet(contents)

Get worksheet names from an excel file

Parameters

contents (str) – contents of data uploaded

Returns

list of worksheet names

Return type

(list)

components.helper.parse_data(contents, filename, worksheet=None, **kwargs)

Reads uploaded data into DataFrame

Parameters
  • contents (str) – contents of data uploaded

  • filename (str) – filename of data uploaded

  • worksheet (str) – worksheet of excel file, if applicable, defaults to None

Returns

(pd.DataFrame)

components.helper.print_callback(print_function)

Decorator function to print callback on backend for debugging purposes

Parameters

print_function (bool) – indicates whether to print callback

Returns

function

components.helper.result_download_button(app, df, dark=True)

Download button for processed data or results

Parameters
  • app (app) – get app properties

  • df (pd.DataFrame) – input DataFrame, to be downloaded by user

  • dark (bool) – if table is loaded in dark background, defaults to True

Returns

(html.Form)

components.helper.result_download_text(input_text)

Download text for processed data or results

Parameters
  • df (pd.DataFrame) – input DataFrame, to be downloaded by user

  • input_text (str) – text to display

Returns

(html.Form)

components.helper.send_email(email_body, subject='Email from Herokuapp', recipient='e0503512@u.nus.edu')

Helper function to send email

Parameters
  • email_body (str) – email body to be sent

  • subject (str) – email subject to be sent

  • recipient (str) – email recipient to receive email

Returns

indicator if email is sent

Return type

(bool)

components.helper.table_css(dark=True)

Gets default dash_table CSS components

Parameters

dark (bool) – if table is loaded in dark background, defaults to True

Returns

4-element tuple

  • (dict): Style for table header

  • (dict): Style for table cell

  • (dict): Style for table

  • (list): CSS component

components.helper.update_when_upload(contents, worksheet, filename, style, ctx, **kwargs)

Reads uploaded data into DataFrame and return dash application objects

Parameters
  • contents (str) – contents of data uploaded

  • worksheet (str) – worksheet of excel file, if applicable, defaults to None

  • filename (str) – filename of data uploaded

  • style (dict) – current style of worksheet selector dropdown

  • ctx (str) – dash callback trigger item name

Returns

4-element tuple

  • (list): list of worksheets options

  • (dict): updated style of worksheet selector dropdown

  • (dash_table.DataTable/list): sample of uploaded data

  • (dict): intermediate data stored in dcc.Store

components.helper.valid_email(email)

Helper function to validate email address

Parameters

email (str) – email address

Returns

indicator if email is valid

Return type

(bool)

components.helper.violin_plot()

Get data for plot, return plot

Adds plotly.graph_objects charts for violin plot at initial loading page

Returns

(dcc.Graph)