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

"ImportError: FigureFactory.create_distplot requires scipy"

I’ve been using plotly in a jupyter notebook without issue, in particular for the use of KDE and histograms using the FigureFactory.
Today I’m porting all this to Dash (which is awesome BTW!).

However, I get this error message when trying to use create_distplot:
ImportError: FigureFactory.create_distplot requires scipy

My code (summarised):

@app.callback(
    Output("graph_kde", "figure"),
    [
        Input("table_comparisons", "selected_row_ids"),
        Input("table_outputs", "selected_row_ids")
    ]
)
def update_graph_kde(comparison_names, output_ids):
    figure = graph_helpers.get_figure_basic()
    if comparison_names and output_ids and len(comparison_names) > 0 and len(output_ids) > 0:
        data = data_helpers.get_graph_framescore_data(manifest_helper, comparison_names[0], output_ids)

        figure = get_figure_kde(comparison_names[0], data)
    return figure

def get_figure_kde(comparison_name, data):
    fig = get_figure_basic()
    if data:
        fig = ff.create_distplot(
            hist_data=[r['df']['vmaf'] for r in data],
            group_labels=[r['name'] for r in data],
            curve_type='kde',
            bin_size=.25
        )
        fig.layout.title = "Histogram, Probability Density and Rug plot, for VMAF score"
        fig.layout.xaxis.title = "VMAF Score"

    return fig

I pip installed scipy, but no luck.
I seem to have solved by doing an import scipy at the top of my file, but that’s weird since it’s not explicitly used in the code…

Am I doing anything wrong?

Hi @Wabiloo thanks for reporting this problem. This is indeed very weird and shouldn’t happen. Are you sure that it’s not a reloading problem (that is if you kill the app and execute again python app.py without explicitely importing scipy, do you still have the ImportError). Sorry to ask you to double-check but I’d like to be sure before investigating more.

I think you must be right. I’ve commented the import now, and restarted the app, and the histogram is displaying correctly.
Sorry, false alert…