Failed call back

Good evening there :slightly_frowning_face:
I am glad to join your incredibly supportive community I am a beginner in this field of data science , any ways I have designed and deployed my first web app with dash but one my charts failed to display presumably because of my call back please examine this code and give me feed back @adamschroeder
@app.callback(
Output(“graph”, “figure”),
Input(“selection”, “value”))
def display_animated_graph(selection):
if selection==‘Trajectory of Pandemic’:
df[‘date’]=pd.to_datetime(df[‘date’], format=‘%Y-%m-%d’)
date=df[‘date’].dt.strftime(‘%Y-%m-%d’)
df_country=df.groupby([‘Countrycode’,‘Country’,‘date’]).sum().reset_index()
fig = px.choropleth(df_country, locations=“Countrycode”, color = “total_cases”,
hover_name= “Country”,animation_frame=date,
hover_data = df[[‘total_cases’,‘new_cases’,‘total_deaths’]],
color_continuous_scale=px.colors.sequential.Plasma)

            fig.update_layout(transition={'duration':1000},paper_bgcolor='#000000',geo=dict(bgcolor= '#000000'),margin=dict(l=0,r=0,t=0,b=0))
            fig.update_traces(marker_line_color='rgba(255,255,255,0)', selector=dict(type='choroplethmapbox'))
            fig.layout.template='plotly_dark'
    else:
            df_country=df.groupby(['Countrycode','Country']).sum().reset_index()
            yesterdays_date=df['date'].max()
            fig = px.choropleth(df_country, locations="Countrycode", color = "total_cases",
                                    hover_name= "Country",
                                    hover_data = ['total_cases','new_cases','total_deaths'],
                                    projection="orthographic",
                                    color_continuous_scale=px.colors.sequential.OrRd_r)
            fig.update_layout(paper_bgcolor='#000000',geo=dict(bgcolor= '#000000'),
                            title=f"Cumulative Cases since the start of pandemic untill {yesterdays_date}")
            fig.layout.template='plotly_dark'

    return fig

if name==‘main’:
app.run_server(debug=True, port=8000)
link to github repo GitHub - Datascientist88/Dash_Dashboard_COVID19_NO_ONE
thanks in advance

HI @Bahageel88 could you please format your code for better readability?

1 Like

excellent thanks
may be
but I suppose it should have raised warning and since the app is working fairly well on the local host we can assume that there is no error in coding
you can find it on github repo

Can you paste your error traceback? It run well on local.

no error is raised bro

In the past I had same situation and I think that maybe we are using free tier of render and its operation quite slow. Could you try to delete this part in your callback and paste it above?

df['date']=pd.to_datetime(df['date'], format='%Y-%m-%d')
date=df['date'].dt.strftime('%Y-%m-%d')

Because I have seen you converted once above and each time it takes a lot of time, so it can affect.

1 Like

Ok I will cut it and paste it above
you I am using render service and I received this message I tried to solve it by deleting the pseudo files :
Server unhealthy

Ran out of memory (used over 512MB) while running your code.

February 1, 2023 at 11:16 AM
please help me

As I said, free tier will be limited on memory, maybe your app is too heavy to deploy on render.

no its not heavy I deployed it but with successive commits I failed so I deleted the pseudo files to clear up the memory
any way what are the alternative cloud service deployment options do you recommend for me?
thanks in advance

1 Like

I think that render is the good one, in the past we can use heroku but now it charged fee for using, you can search about googlecloudrun but it’s more complicated to deploy than render (my opinion).

1 Like

since I deployed it successfully for the first time in render I would presume that my app is not heavy for render
but the subsequent deployment failures are attributable to factors I have no idea about

hi @hoatran
I have removed the two lines and paste them up but the chart did not appear have a look at it
https://bahageel-corona-covid19-dashboard.onrender.com/

hi @Bahageel88
I would reiterate @AIMPED 's advice. Please return to your initial/first post and update the code so it is in pre-formatted text, suing this tool below.

Also, building on @hoatran 's advice, I recommend you open a new .py file and just try to recreate and plot the px.choropleth. Filter the data manually (without a callback or dropdowns) and try to plot that data on a choropleth map within a separate .py file.

2 Likes

Not sure why but I tried to deploy by myself and it showed the graphs but graph with an
animate not showed, you can check it here: https://test-covid.onrender.com/

I think that it’s not your code problem but choropleth with animation takes long time to deploy so it not worked with render.

P/s: I think you should change this one too: from df_country=df.groupby(['Countrycode','Country','date']).sum().reset_index()to df_country=df.groupby['date','Countrycode', 'Country']).sum().reset_index() and then sort values by date. If not your animation will not correct.

1 Like

Good morning Adam
You know what I did is that I removed all the code from the call back function and occurred to me that I can use instead a dictionary with the options as keys and values as figure names fig etc but I am afraid it’s still resource-consuming thus I might consider deployment on Google run
Please look at the photo and give your feedback
Thanks :pray: @adamschroeder for your kind cooperation

I have removed the code from the the call back function to outside and then used a dictionary
to refer the charts have a look at the attached photo and give me your feedback

Dear @Bahageel88, I understand that you are trying to solve your problem and make your app work better.

I would reccommend, however, changing the way of asking your questions or providing information. Your current way of doing so, may disencourage people investing their time in trying to help you. :hugs:

1 Like

Good morning my beloved companion
Yes I am new to this field of data science and very much enthusiastic to learn from you I am very much open to criticism to improve and learn
Would you please suggest a better way for me to raise my questions appropriately
I am learning continuously particularly from my mistakes
Thank you very much indeed
With best regards

hi @Bahageel88

@AIMPED 's advice is good advice. You can start with this post.

1 Like

Dear @adamschroeder
I will will read the instructions and follow through
With kind regards
:rose::rose: