Python Data Visualization Transcripts
Chapter: Streamlit
Lecture: Sidebar intro

Login or purchase this course to watch this video and the rest of the course contents.
0:00 For the final demo. I want to show how to control the layout. Using the sidebar function in streamlit. So I've created a new file
0:10 ST simple sidebar. I have my imports that we've talked about. I am loading my data using the cache decorator and then I have my data frame
0:20 My min year and the max year. One of the things I want to do for managing the valid makes is add
0:29 an option to select all and so what I'm gonna do is create a new list where all is the first element and then I have all of my unique make values
0:42 So that will show up and then we can choose to show all of the makes. And then one of the things that streamlit allows you to do as well
0:53 is to set a default value. So maybe I don't want to have all of them but maybe for this example I just want to use the top five.
1:02 So what I do here is I take the top five so do a value counts on make, take the top five and turn it into a list.
1:13 So this will give me a list of all the type values and I can pass that in as a default. So let's go ahead and create my user interface.
1:24 So I'll add my title sidebar example. Now what I'm gonna do here for the make, I still have it as a multi select but you'll notice that I say
1:35 ST.sidebar. So that's telling streamlit to put this on the sidebar and then I still use my multi select and also pass in the default makes that I
1:49 created up here, so that will give me all five. Then I will have the year range like we've done in the past.
1:58 So let me show you what that actually looks like. So now we have this sidebar on the left,
2:08 we still have our title and we can choose to close it and then we have
2:15 a new option here that says all and we still have the ability to select everything else. And we have our slider.
2:25 So what this allows us to do is to have a sidebar over here that we have all the widgets that we might want to control.
2:32 And then over here we can put in the items that we want to visualize based
2:37 on these inputs. And this is just a much more compact and convenient way to do things.


Talk Python's Mastodon Michael Kennedy's Mastodon