Re-Using Code in Dash-Plotly

Hi Everyone,

I am working on a web app where multiple charts layout are updated using a code similar to below

fig.update_layout(title_text , title_x =  title_y = , title_font_color = ', plot_bgcolor = ,  paper_bgcolor = , yaxis = dict(color = ),
  xaxis = dict(color = ))

My question is it possible to re-use the code, it somewhat annoying that I have to write the code above for each charts, I tried to see if I could write that in a new python file and import as a module but it’s impossible because of the structure.

A simple way to think about it is like trying this

x = (a =2, b=4)

It throws up a syntax error in python

Thank you.

Hi @Oladayo does this work for you?

x = (a:=2, b:=4)

You could create a function which returns the updated figure.


You are right with the function approach. I moved the plots into a new python file and just import the module.

Thank you.