Build Better Python Web Apps With Your Data
Anvil is free to use. Start building now!
Prefer text to video? Read on to learn how to use Data Files
Python is great for working with data. With Anvil you can build web apps to interact with datasets and machine-learning models entirely in Python.
In this article, I’ll show you how to use Anvil’s Data Files service to attach static data to your web app. We’re going to upload a CSV dataset and plot the data from it using Pandas. Then, we’ll display the plot online for everyone to see - all in Python.
Uploading our CSV
We start by uploading our dataset into our app’s Data Files service. I’m using some example data of Apple’s stock price over time which you can download here:
Plotting our data
@anvil.server.callable def plot_data(): # Read the CSV file into a DataFrame using the Data Files path df = pd.read_csv(data_files['dataset.csv'])
We’ll use Plotly’s Pandas backend to plot our dataset as a line graph and return that figure from our server function.
@anvil.server.callable def plot_data(): # Read the CSV file into a DataFrame using the Data Files path df = pd.read_csv(data_files['dataset.csv']) # Then plot the graph using the Plotly backend df = df.set_index('Date') fig = df.plot.line(title="APPL Stock Price") return fig
Building our front-end
def __init__(self, **properties): # Set Form properties and Data Bindings. self.init_components(**properties) # Any code you write here will run when the form opens. self.plot_1.figure = anvil.server.call('plot_data')
Running our app
When we run the app, it will load the dataset and plot it with Pandas.
You can use Anvil’s Data Files to load and run machine learning models, complicated datasets, and more. To find out more about Anvil and using Data Files, check out the links below.
Why not have a play with the app builder? It’s free! Click here to get started:
Get Started with Anvil
Nothing but Python required!