Black Lives Matter. Please consider donating to Black Girls Code today.

Returned HTML is displayed 'raw' and not rendered

Hi I am trying to return an HTML object (created from another Python library - “statsmodels”) to Dash. However, the elements are not rendered and it returns the raw HTML object.

Output Div:



     Output('regression-result', 'children'),
     [Input('my-date-picker-range', 'start_date'),
     Input('my-date-picker-range', 'end_date'),
     Input('portfolio-checkboxes', 'value'),
     Input('dropdown-input', 'value'),
     Input('dropdown-output', 'value')]

def create_regression_table(start_date, end_date, selection, choice_X, choice_Y):
    global df_r

    lag = 6
    df_r_filter = RC.create_timeseries(df_r, start_date, end_date, selection)

    if choice_X == 'rp' or choice_Y == 'rp':
        df_weights = RC.create_portfolio_weights(df_r_filter, lag)
        df_rp = RC.create_portfolio_riskparity(df_weights, df_r_filter)
        return_rp = df_rp.values
        if choice_X == 'rp':
            X = return_rp
            y = return_rp

    if choice_X == 'eq' or choice_Y == 'eq':
        df_bm = RC.create_benchmark_portfolio(df_r_filter)
        return_bm = df_bm.values
        if choice_X == 'eq':
            X = return_bm
            y = return_bm

    if choice_X == 'mkt' or choice_Y == 'mkt':
        df_mkt = RC.create_rebased_index(df_r_filter, True)
        return_mkt = df_mkt.Return.values
        if choice_X == 'mkt':
            X = return_mkt
            y = return_mkt

    regression_result = RC.perform_regression(X, y)

    return regression_result

External module:

def perform_regression(X_returns, y_returns):

    X = X_returns
    y = y_returns
    X2 = sm.add_constant(X)

    est = sm.OLS(y, X2)
    est2 =

    return est2.summary().as_html()

Displayed Output

Thanks for your help!

check out the “dash dangerously set inner html “ component

Worked like a charm! Thanks!