Reactive Web Dashboards with Shiny Transcripts
Chapter: Hello Shiny
Lecture: First Shiny app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 But this is a course where we're going to start from scratch. And so I'm just going to start off by going ahead and
0:08 deleting everything and starting from a blank slate. And again, what we're using here is Shiny Express.
0:18 And for Shiny Express to work, you need to import something from the shiny.express module.
0:25 And this is going to start almost all the scripts that you're going to use in this course is import, or I'm sorry, from shiny.express.
0:34 And you just need to import some object. So in this case, we're going to be importing UI to just get started. Oops. Import UI.
0:47 And then now that we have this one line, import shiny express, we can run this application and it'll run it.
0:55 You can see we have a little web server running in our terminal down here. But we don't have anything in this application yet.
1:01 So to just generate some things in this application, we're going to start pulling things off of this UI submodule.
1:09 The UI submodule includes all of the UI elements. So there are some HTML tags, inputs, various different things like that,
1:17 layout objects, cards, sidebars, things like that. In this case, we're going to be using a UI H1, which is just a heading one.
1:24 And we're going to call this my dashboard. When I save it, since I used the VS Code extension,
1:35 it will automatically re-execute the application as soon as I make a change. So we have UI H1 dashboard, and we'll do maybe UIP.
1:47 So this is all good, but effectively what we're doing here is writing a static document. There's no interactivity here.
1:53 It's just a kind of odd way of writing HTML. And what we want to do is we want to start using some interactivity.
2:02 And to do that, we need to import another thing, which is called render. So render is what lets Shiny kind of react to a particular action.
2:11 So whenever anything is inside a render decorator, that means that it's going to be reactive in some form. And how that reactivity is going to manifest
2:18 is going to differ based on each case. Let's start by pulling in the data. So whenever you're working with static files on your site,
2:26 I recommend using pathlib and this path object. And what that's going to do is basically let you define the location of this file relative
2:35 to the location of this app file. And that means that if you're running it, you don't need to worry about your terminal being in the right directory
2:41 to run the application. And we're also going to import pandas to do the actual reading.
2:52 So we have df, and we're going to actually start by just breaking this up into two little bits. Call this file path.
3:00 And so the path to the file gives you the path to this app.py file. And my copilot is very helpfully giving me the thing that I actually want.
3:10 And then I'm just going to use this penguins.csv file. Call this file path. And then df, we can just do pd readcsd file path.
3:26 And just to see that that worked, I'm going to try saving it. And you see we have this pandas data frame read in and printed out in the console.


Talk Python's Mastodon Michael Kennedy's Mastodon