App skeleton building
First of all, we need a main function – a function that contains all the business logic of our app and the frontend too. This is the power of Streamlit – building the frontend directly inside Python code. There’s no need for different programming languages, files, and so on; everything is in one place using the same language. Writing this function is very easy – we can add the code shown in Figure 4.9:
Figure 4.9: Importing the necessary libraries and the main function
The first part of the code is quite self-explanatory – we are just importing all the libraries that were introduced a couple of pages before. Just note that when we import matplotlib
(the library needed for plotting), we are specifying that we wish to use the Agg
engine (without this instruction, matplotlib
would use its default engine). With Streamlit’s initial versions, this Agg
engine used to work better, but with the very...