The shiny package requires a server running R. If you want see how to deploy an application online, I suggest you access https://www.shinyapps.io/, sign in, and develop your own app. The basic version is free to use, but it has limited resources, so you must go with a simple app. If you like it and want to improve, you can try the paid version or another data server. The Shiny RStudio gallery (https://shiny.rstudio.com/gallery/) can give you some inspiration and show you how people are using the Shiny app.
If your app is online, it will drain some resources from the server. It's good practice to keep all of the code you really don't need to run every time outside the server function. The code in the UI is executed only when the R section starts, but the codes inside the server function is executed every single time when the user interacts with...