Will Build R Shiny Apps for Food
6 min readFeb 15, 2024
If you build the skills, where can you find the work?
There is no doubt that R Shiny has utility. There are some wonderful applications you can build to provide a website with interactive options that enlighten the user.
This app allows users to explore a dataset through various visualizations. You can easily change up what is on the X axis or Y axis with drop-downs.
# Code chunk 1: Load packages and data
library(shiny)
library(ggplot2)
library(datasets)
# Load Iris dataset
data(iris)
# UI definition
ui <- fluidPage(
# Sidebar for selecting variables
sidebarLayout(
sidebarPanel(
selectInput("x", "X Variable:", names(iris)),
selectInput("y", "Y Variable:", names(iris))
),
mainPanel(
plotOutput("scatterPlot")
)
)
)
# Server logic
server <- function(input, output) {
# Code chunk 2: Update plot based on user selections
output$scatterPlot <- renderPlot({
ggplot(iris, aes_string(x = input$x, y = input$y)) +
geom_point() +
labs(title = "Interactive Scatter Plot")
})
}
# Run the app
shinyApp(ui = ui, server = server)