How to generate a a graph from two files?

I am using the MVC model, and I want to separate the data that generate the graph from its view. What I want to do is to put all the data from the graph in one file (the model) and just display it from another file (view), with a line or two of code.

For example with the following graph:

File 1 (model)

import as px

long_df =

fig =, x=“nation”, y=“count”, color=“medal”, title=“Long-Form Input”)

File 2 (view)

Something to call the graph from the file 1 to draw it, instead of having to put all the code in the file 2 to draw it.

Thank you.

Edit: Calling a function could be interesting, but in my view file there is the HTML/CSS, so If I simply call my_graph_function() which would include the code of the graph, the function won’t be included in the HTML/CSS and will just draw the graph without taking the HTML/CSS layout into account.