Show the code
install.packages("shiny")
Participants will create a basic Shiny app to add interactivity to data visualizations and outputs.
Shiny is an R package that makes it easy to build interactive web applications directly from R. Below are the steps to create a basic Shiny app.
install.packages("shiny")
Create a New Directory for Your App:
my_shiny_app
).Create the app.R
File:
app.R
.library(shiny)
# Define UI
<- fluidPage(
ui titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
),mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic
<- function(input, output) {
server $distPlot <- renderPlot({
output<- faithful[, 2]
x <- seq(min(x), max(x), length.out = input$bins + 1)
bins hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
Run the App Locally:
app.R
in RStudio and click “Run App” to start your application locally.Once your app is working locally, you can publish it online using shinyapps.io.
install.packages("rsconnect")
library(rsconnect)
# Set account info (replace with your own account details)
::setAccountInfo(name='yourname',
rsconnecttoken='yourtoken',
secret='yoursecret')
Deploy the App Using rsconnect:
::deployApp('path/to/your/app') rsconnect
Access Your Live App:
By following these steps, participants will gain practical experience in creating interactive web applications using Shiny and learn how to deploy them online using shinyapps.io.