Skip to playerSkip to main content
  • 1 week ago
Shiny for Python gets a full setup walkthrough here, from installing the package and preparing VS Code to launching and deploying a first interactive app. The focus is on getting your environment ready the right way so you can start building Shiny web applications in Python without getting stuck on setup issues.

The process covers the Shiny website, the VS Code Shiny extension, creating an app.py file, adding a requirements.txt file, and installing the needed packages with pip. It also shows how to sign up for shinyapps.io, authorize your account with rsconnect, and deploy a simple starter app so you can share a live link online. Along the way, the video explains why Shiny Express is the easier path for getting started and points out how the deployment and logs work.

If you are learning Python dashboard development, interactive web apps, or data science app deployment, this is a practical beginner guide to the Shiny for Python workflow. It is especially useful for anyone setting up VS Code, exploring Shiny apps, or looking for a first deployment tutorial before building more advanced layouts, components, and visualizations.

SEO: Shiny for Python tutorial, Python web app setup, VS Code Shiny extension, shinyapps.io deployment, app.py and requirements.txt, interactive dashboard development, Python app deployment guide, beginner Shiny Express setup, data science web apps, first Shiny app in Python.
Transcript
00:00What's going on, everybody?
00:01Welcome back to another video.
00:02Today, we're gonna be starting our Shiny for Python series.
00:10Now, Shiny is an open source web application framework
00:13for Python and R as well,
00:15but we're gonna be focusing on Python.
00:17And what we're able to do is create interactive dashboards
00:20and basically complete websites all within Shiny.
00:23Throughout this series,
00:23we're gonna start with the very basics of getting it set up.
00:26We're gonna be learning all about the different components
00:28and how you can customize your web app.
00:29And then in the last lesson,
00:30we're gonna build a complete Shiny app.
00:32So this is gonna be a full dashboard
00:34with a bunch of different things on it.
00:35It's gonna be really interactive.
00:36It's gonna be amazing.
00:38Now, in this video specifically,
00:39we're gonna be getting everything set up.
00:41We're gonna be using VS Code.
00:42We're gonna download all of the libraries
00:44and every packages that we need.
00:46And then we're even gonna deploy our very first web app.
00:49Without further ado,
00:50let's jump onto my screen and get started.
00:51Now, before we jump into installing
00:53and creating our environment
00:54and launching our very first Shiny app,
00:56I just wanna start off by looking at the Shiny website.
00:59So there's so much here.
01:01This is a fantastic place to learn,
01:03as well as get a lot of ideas for creating your dashboards.
01:06As well as, you know,
01:08Posit, who creates all of this,
01:10is just amazing with their websites.
01:12So if you're looking at Shiny for Python,
01:14they have a whole suite of different things that you can do,
01:17as well as they have a playground
01:18where you can test all of these different Shiny things
01:21that you wanna test.
01:22So if we wanna come down here and look at reactive calculations,
01:27then we can come in here and we can learn how to do that
01:30in their environment.
01:30So they have just a ton of stuff.
01:33One of the biggest things that we're gonna be looking at
01:35in the next several lessons is components and layouts.
01:38And as we're building this web app,
01:40you're gonna say, oh, I really want a button here.
01:41And so I want an input for them to be able to click on it,
01:45or I wanna switch it to dark mode.
01:46And these are all things that they have right here.
01:50Or we can go further down and you can do outputs.
01:52So if you wanna output a matplotlib visualization,
01:55or Plotly, or Seaborn, you can do that.
01:58Or just, you know, a data grid.
02:00You can do all these things, they show you how to do that.
02:02And so these are just an invaluable resource
02:04when you're building these web apps.
02:06And I personally, when I was building this out,
02:09and building out this series,
02:10I was in here a lot, testing out different things,
02:13seeing how they worked.
02:14Now the next thing,
02:15and we're gonna be getting into this
02:16in, you know, right over here in this part.
02:18This is how we actually host it and create the website.
02:21And so we're gonna be using shinyapps.io.
02:24This is how we are going to actually
02:26share your Shiny application online.
02:28Because we have to deploy it, right?
02:30So that you can share the link and people can use it.
02:32And you can do this for free.
02:34Now you can also pay if you, you know,
02:36want to host multiple web pages or multiple apps.
02:40You can do that, and it does cost money.
02:42Or you can do it for free.
02:43And we're gonna be looking at the free version
02:45of how to do that.
02:46And we'll even, you know, launch and deploy
02:48our app by the end of this lesson.
02:51So I just wanted to show you all that,
02:53because that stuff is really, really important.
02:55Now, if we come back here to Shiny for Python,
02:58we have an install button.
03:00Now let's go to install.
03:01And install is quite easy.
03:03All we have to do is go into our ID,
03:05and we have to pip install shiny.
03:07And that's it.
03:08It's as easy as that.
03:09And then I'm gonna show you a bunch of other stuff
03:11to actually really get your environment ready
03:13for everything that we're gonna be doing
03:15in the next several lessons.
03:16But that is really all we have to do.
03:18Now, what we are gonna do is,
03:20we're gonna come right over here.
03:21We're gonna go to Anaconda.
03:22And you don't have to use Anaconda,
03:24but I'm just using it for the simplicity.
03:26I usually use, for a lot of my Python tutorials,
03:28I use Jupyter Notebooks.
03:29But we're gonna be using VS Code, which is right here.
03:32And I'm using VS Code specifically,
03:34because they have a Shiny extension,
03:35which really, really helps with this whole development process.
03:38And so I personally really, really think
03:41that's something you need to have.
03:42So we are gonna be using that.
03:44So let's go ahead and we're gonna launch VS Code.
03:46Now, once we open up VS Code,
03:48one thing that we need to do is go right over here to extensions.
03:51And when I come up here, we're gonna type in Shiny.
03:54Now, we should see Shiny right here.
03:57It says, run and develop Shiny apps in Python or R.
04:01Now, you want to make sure you have this.
04:04The reason for this is they have something right here.
04:07You can run and debug your Shiny apps
04:09just using this little button right here.
04:11It's fantastic.
04:13And so you can come in here and you can see,
04:15read a lot of their documentation on everything.
04:17One of the other things to mention
04:19is we're gonna be using Shiny Express.
04:21They do have something called just Shiny or Shiny Core,
04:25which is a lot more technical in my opinion,
04:28whereas Shiny Express, you can get so much done
04:30with Shiny Express without ever having to really dig into
04:33the really complex stuff or the more complicated stuff.
04:36And that's what I personally prefer.
04:37So we're gonna be looking primarily at Shiny Express.
04:41Now, the next thing that we're gonna do
04:42is we're gonna come right over here
04:43and we're going to create a new file.
04:46So we're gonna come in here
04:46and we wanna create a PY file or a Python file.
04:50So we're just gonna call this app.py.
04:53And I'm naming this specifically app.py for right here.
04:58For single file apps, e.g. app.py or app.r,
05:02run the Create Shiny Live link from active file,
05:05from the command palette.
05:06All that being said, we need to be called app.py.
05:09So that when we actually try to deploy this,
05:12it will understand that this is the file
05:14that it's looking for.
05:15So we need to name it that app.py.
05:18In here, I don't know if it talks about this,
05:21but we're also gonna need a requirements.txt file.
05:25Now, this is in documentation on their website.
05:27So we do need to have this.
05:30So I'm gonna create one more just real quick.
05:31It's just gonna be called requirements.txt, just like that.
05:37Now, this is gonna be for, again, when we deploy it,
05:40it's gonna read in the packages.
05:42It's gonna use those packages when deploying.
05:44So if we use a package in here,
05:46we need to also put it in this requirements.txt.
05:49It'll make sense as we start getting into it.
05:52Now, let's come back really quick.
05:54We need to go in here and we're going to come back here
06:00and we're gonna sign up for the shinyapps.io.
06:04Once we do that, we're gonna actually take some code
06:07from in here.
06:08Maybe we'll go to some components layouts,
06:11or maybe we'll mess around with something in the playground
06:13and we'll copy it.
06:14And we will actually launch this and deploy this
06:17so it's a real website.
06:18But we need to sign up really quickly for an account.
06:22So we're gonna go over here.
06:23We're gonna go to sign up.
06:25And I'm gonna sign up with my Google
06:26and you do the same.
06:28And then once we're onto it together, we'll take a look.
06:30All right, so I just logged in.
06:31It says, let's get started.
06:32You'll need an account before you can deploy any applications.
06:35Account names can contain letters, numbers, hyphens, etc.
06:40So what we're gonna do is we're gonna call this
06:45alextheanalystshinyapp, and we'll call it that.
06:47So what it's gonna be is https colon forward slash forward slash
06:52alextheanalystshinyapp.shinyapps.io.
06:54Now you can name this anything you want.
06:55It has to be unique.
06:57But if you wanna name this your name,
06:58I could do it alexfreeberg.
07:00So I could come in here and say alexfreeberg.
07:03And if that wasn't taken, I can just save that.
07:05So we'll just go back.
07:06I'm gonna call it this and we're gonna click save.
07:09And now there are a few things that we need to do
07:11to actually get started.
07:13We have to install something called the rsconnect.
07:15This is the actual package that you need to deploy it
07:18into the shinyapps.io.
07:20Now we need to do this with Python.
07:23So we're gonna come in here.
07:24We're gonna do pip install rsconnect.
07:27One thing that we also need to do
07:29is start a terminal really quick.
07:31This is my file path.
07:33We also need to pip install shiny.
07:36So be sure to do that.
07:38I already have it installed.
07:39So it's gonna say I meet all the requirements.
07:42But make sure you pip install shiny.
07:44And then once it's done, we can also come in here
07:47and pip install rsconnect-python.
07:50Now I also have this already installed.
07:51So I meet those requirements.
07:53But we have to have that in order to deploy it
07:57and use shiny in general.
07:58So make sure you have those two things installed.
08:02Now we're gonna come back here.
08:03The next thing we have to do is authorize our account.
08:06So we created this account.
08:08My account is alexanalyst shinyapp.
08:10But we have to come in here.
08:12And we need to run this as well.
08:14So we're gonna copy this to my clipboard.
08:16I'm gonna click OK.
08:18And I'm gonna run this.
08:21It's going to check the credentials.
08:24It's gonna say it added it.
08:25And we're good to go.
08:27So now let's go back up here to the website.
08:29The last thing we actually have to do is to deploy this.
08:32And we can't deploy if we don't have code.
08:35So what we're gonna do is let's come up here
08:37to some shiny examples.
08:39And this is a very basic app.
08:41Let's take a look at this one right here.
08:44So let's just run this.
08:46And this is a very, very, very simple application right here.
08:51We're using matplotlib, numpy, and shiny.
08:53And so we don't know any of this yet.
08:55In the next lesson, we'll be diving into a bunch of different things
08:58and how we can actually build all of this out.
09:00But let's just copy this.
09:02And we're gonna go back.
09:04And we're going to paste this right here.
09:07Now, what we need to do is we need to save this.
09:10So I'm gonna do CTRL-S.
09:12And that's gonna save this file.
09:14And then I'm going to take matplotlib, numpy, and shiny.
09:18And I'm gonna put them in here.
09:19So I'm gonna say matplotlib, shiny, and I think it was numpy.
09:27Numpy, numpy.
09:28So now I'm going to save that as well.
09:30So I did CTRL-S.
09:31That's gonna save it.
09:32You can also come up here and hit save, which is, again,
09:35the shortcut is CTRL-S.
09:37I'm just gonna use CTRL-S for this.
09:40But now what we can do is we can come over here
09:43and we can run our shiny app.
09:45So let's try this.
09:46Let's run our shiny app.
09:49You're gonna see right down here, a bunch of stuff happens.
09:53Really what's happening is it is pulling up that shiny library
09:57and that extension that we're using.
09:59And we are able to run this and actually view what it's gonna look like
10:03on our website or on our web app when we actually create it.
10:07So it does a bunch of stuff down here,
10:09but it eventually creates that connection.
10:11And we can see our web app right over here.
10:15Now, in order to actually use this and deploy this,
10:18we have to do something right over here.
10:21So we're gonna come over here.
10:22We're gonna say RS Connect.
10:25And we're gonna say RS Connect.
10:26And it's gonna bring us a bunch of different options.
10:29So it's just gonna tell us that this can be used
10:31for Posit Connect, Posit Cloud, shinyapps.io.
10:36And here's some of the options that we can do.
10:38Now, we want this one right here, which is to deploy this.
10:42So what we can do is we can say RS Connect.
10:46Then we'll say deploy.
10:48Now it's gonna ask us, what are we actually deploying?
10:51So we said RS Connect deploy.
10:53Down here, we are deploying, that's right, a shiny app.
10:56So we're gonna come right over here.
10:58We're gonna say RS Connect.
11:00We're gonna say deploy shiny.
11:03Then we're gonna do dash n.
11:05And what we need now is we need that name that we used
11:09right over here.
11:10So for my account, it's Alex the Analyst shiny app.
11:14You're gonna need yours.
11:15So we're gonna come in here.
11:16I'm gonna say Alex the Analyst shiny app space dot.
11:22Now what this dot is actually doing is it's getting
11:24our current file path.
11:26So this file path right here where these,
11:29the app.py and the requirements.txt are located.
11:33And it's gonna deploy that.
11:35Now you can get more specific if you want to do it
11:38from a different folder or something like that.
11:40You can specify the folder name.
11:41But let's go ahead and run this and see what happens.
11:46Real quick, while this is all happening,
11:48it's just making sure our server is there.
11:50It's looking at our requirements.txt.
11:52So it's looking at the packages.
11:55And then it's actually gonna be building it out.
11:57And then it's going to deploy it for us.
12:00And there we go.
12:02Now, this is not the prettiest web app in the world,
12:05but you now are able to deploy this.
12:08And now you can use this right here.
12:10And you can share this link with your friends and say,
12:12hey, I built this web app.
12:14Now, this is a very, very, very, very simple one.
12:17In the next lesson, we'll be using real data.
12:19And we're gonna create some actual visualizations
12:22using those components and the layouts.
12:24And if you come in here,
12:26we go to our applications and we come into all,
12:29you can see that this right here is in fact running.
12:32And so you can come in and you can,
12:35let's say you're getting an error or something.
12:37You can come in here and you can look at the logs
12:40and you can see why is my app failing.
12:42And this has been really helpful for me
12:44when I was making mistakes early on.
12:46This was really, really helpful for me to understand
12:49why a package wasn't installing right,
12:51or I was using the wrong library, or it was out of date.
12:54And so you can come in here and get a lot of information.
12:57So it's super, super helpful.
12:58But we now have a live web app.
13:01Now, this is a super simple one.
13:03Again, in the next lesson, we're gonna be using real data.
13:06And we're gonna be really diving into the layouts
13:09and components here.
13:10So these two specifically,
13:11because there's so much that you can do with it.
13:14And we're gonna be using real data to really dive into this
13:17and make sure you know what you're doing.
13:19So I hope you're able to follow all of that,
13:21get up and running.
13:22That is kind of the hardest part.
13:24If you come over here,
13:25you'll now see we have this shiny.json.
13:29If we click on it, once we actually deployed this,
13:32it says, okay, this is the server.
13:35Here is where the files are.
13:37Here's your app URL.
13:38So I hope you're able to get up and running with Shiny.
13:41If you're not used to VS Code, you know,
13:43just do exactly what I do.
13:45VS Code may be a little bit intimidating for some,
13:47but I promise you by the end of this series,
13:50even you'll be a VS Code master
13:52because it's fairly intuitive once you get into it.
13:54So thank you guys so much for watching.
13:56Huge shout out to Posit for creating Shiny for Python.
13:59It was only in R for a long time,
14:01but now they brought it to the Python community
14:03and I am super excited about it.
14:05So huge shout out to Posit.
14:06If you liked this video,
14:07be sure to like and subscribe below,
14:09and I will see you in the next video.
Comments

Recommended

  1. RareGear
    3 months ago