Python Data Visualization Transcripts
Chapter: Streamlit
Lecture: Widget Intro

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now let's go through another example of using streamlit. And this time we'll add some interactive elements. So I started a simple file called
0:11 ST. Simple_2 and put my imports in here for streamlit plotly express and altair the first thing we're going to do is to load our data
0:24 in the previous example we just loaded the file directly. But what I'm gonna do here is create a function called load data and use the
0:32 ST Cache decorator so that every time I run it will only load this data one time and save me a lot of time while it's serving up the
0:43 data. If I didn't have this every time I refreshed one of my inputs it would reload the data and really slow us down.
0:51 So now I've just taken the source file I've read it in that CSV. And then I'm going to return a data frame. So now we
1:00 want to actually do a little bit of work with that data frame. So the next portion of code I want to walk through is now I'm going to
1:08 load the data. I've defined that function. I'm gonna load the data and I want to get the current year or the range of years in the data set.
1:18 So the minimum year and the maximum year. And then I also want to get a sorted list of all the makes because I'm
1:26 gonna build some widgets so that we can select the different makes in the year range
1:30 And instead of hard coding it I want to capture that information from the data
1:35 set itself. And for the final input portion I'm going to create a title just
1:41 call this simple example and then I'm going to use a multi select what this means is you can choose one or many valid makes and indicate to the user.
1:53 They should select to make the other widget I'm gonna show is the slider, ST.slider and I define the minimum value and the maximum value.
2:04 And then this is the range that we start with. So let's save this and run it and we'll show you what the simple file looks
2:14 like. So I'm just gonna refresh how you run this. I'm gonna do streamlit run and then the file that tells me my URL's. I'm gonna minimize that.
2:33 And now I have this simple example where we have two different widgets and I'll walk through those in a moment.

Talk Python's Mastodon Michael Kennedy's Mastodon