Forums

Plotly dash, graph works on local host but doesn't show anything in pythonanywhere

Here is the code of 2 charts. The boxplot works well but gene_mutation_fig doesn't show anything. While both of the charts work on the local host, the gene_mutation_fig doesn't work in pythonanywhere. I would be grateful for any suggestions.

import dash
from dash import html, dcc, callback, Input, Output, State
import pandas as pd
import plotly.express as px
from sklearn.preprocessing import StandardScaler
import plotly.graph_objs as go
import numpy as np

boxplot_fig = px.box(melted_data,
                     y='variable',
                     x='value',
                     title='Boxplot of Clinical Attributes Distribution(Standardized)',
                     orientation='h',  # Set orientation to horizontal (vertical boxplot)
                     )

start_column_index = 520

# Select the subset of columns from 'start_column_index' to the end
selected_columns = data.iloc[:, start_column_index:]

# Count non-zero occurrences for each gene in the mutation data
gene_mutation_count = pd.Series([np.sum(selected_columns[col].astype(str).str.strip() != '0') for col in selected_columns], index=selected_columns.columns)

gene = gene_mutation_count.index.str.replace('_mut', '')
val = gene_mutation_count.values
gene_mutation_count_df = pd.DataFrame({'Gene Name': gene, 'Mutation Count': val})
gene_mutation_fig = px.bar(gene_mutation_count_df, x='Gene Name', y='Mutation Count',
             title='Gene Mutation Distribution',
             labels={'Gene Name': 'Gene Name', 'Mutation Count': 'Mutation Count'}
            )

layout = html.Div(children=[

    html.Div(className='row', children=[
        html.Div(className='six columns', children=[
            dcc.Graph(id='boxplot', figure=boxplot_fig)
        ]),
        html.Div(className='six columns', children=[
            dcc.Graph(id='gene-mutation-distplot', figure=gene_mutation_fig)
        ])
    ]), ...

Do you see anything relevant in the bottom of your web app's error log?

There are no errors in the error log

Is the page in question /data-distribution?

Yes. I have reinstalled the app and virtual environment. Now it works. Thank you

Great to hear that, thanks for letting us know!