<- function(input, output) {
server $distPlot <- renderPlot({
outputggplot(faithful, aes(x=waiting)) + geom_histogram(bins = input$bins)
}) }
Polish and share your own shiny app
SISBID 2025
https://github.com/dicook/SISBID
Your turn
- Join forces with your neighbours or work alone
- Make your own app, or interactive document, on a topic of your choice
- Some ideas are data from TidyTuesday or fivethirtyeight
- Your app needs to have
- at least one interactive plot
- some GUI element like a menu or checkboxes
- some nice styling
😱 If you are not confident going alone, work through the steps in the next few slides instead, to make an app.
Out of ideas? Try the TidyTuesday Cocktail Data and this prompt
RStudio Connect and ShinyApps
- Sign up for an account on https://www.shinyapps.io/
- Authenticate your account
- Install the library rsconnect (this is the part that may require admin access to your machine)
- Follow the instructions on ShinyApps.io to authenticate and upload your first app!
Initiate
✅ Using the RStudio File
menu,
- choose
New file
, - choose “Shiny web app”
- Give it a name, and choose
Single file
This will create a folder in your workspace with the same name as you gave your app. It will also open the app.R
file in your text editor pane.
🛑 Click the Run App
button on the RStudio window.
✅ Click Publish
to upload your app to the shinyapps.io server.
㊗️ You’ve just published your first app
Make it yours
Change the plot to use ggplot
, this involves changing the server function to be this:
You will also need to add library(ggplot2)
at the top of the file, just after library(shiny)
.
🛑 Click the Run App
button on the RStudio window. (Fix any errors)
✅ Click Publish
to re-upload your app to the shinyapps.io server.
㊗️ You’ve just published your first modified app
Make the plot interactive
Change from a static ggplot plot, to an interactive plotly plot, by
Change the server function to look like this. Note renderPlotly
<- function(input, output) {
server
$distPlot <- renderPlotly({
output<- ggplot(faithful, aes(x=waiting)) +
p geom_histogram(bins = input$bins)
print(ggplotly(p))
}) }
Change the ui
function to render plotly output
mainPanel(
plotlyOutput("distPlot")
)
Add library(plotly)
to the top of the file.
🛑 Click the Run App
button on the RStudio window. (Fix any errors)
Change the UI
Convert the slide into a numeric input, by changing the ui
function to be:
sidebarLayout(
sidebarPanel(
numericInput("bins", "nbins", 30)
),
(The numericInput
replaces the sliderInput
code)
🛑 Click the Run App
button on the RStudio window. (Fix any errors)
✅ Click Publish
to re-upload your app to the shinyapps.io server.
㊗️ You’ve just published your second modified app
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.