Create an app with 3 pages with routing so that I can use different URLs to access different pages of app
Drop files here
or click to upload
library(shiny)
library(bslib)
ui <- page_navbar(
title = "Multi-Page App",
# First page - Home
nav_panel(
title = "Home",
layout_column_wrap(
width = 1/2,
card(
card_header("Welcome"),
p("This is a multi-page Shiny application with URL routing."),
p("Use the navigation bar above to explore different pages.")
),
card(
card_header("Features"),
p("- URL based navigation"),
p("- Responsive layout"),
p("- Modern UI with bslib")
)
)
),
# Second page - Data
nav_panel(
title = "Data",
layout_column_wrap(
width = 1,
card(
card_header("Data Visualization"),
plotOutput("plot")
)
)
),
# Third page - About
nav_panel(
title = "About",
layout_column_wrap(
width = 1,
card(
card_header("About This App"),
p("This is a demonstration of a multi-page Shiny application."),
p("Each page is accessible via its own URL:"),
tags$ul(
tags$li("Home: /"),
tags$li("Data: /data"),
tags$li("About: /about")
)
)
)
),
nav_spacer(),
nav_menu(
title = "More",
align = "right",
nav_item(
tags$a(
icon("github"), "Source",
href = "https://github.com",
target = "_blank"
)
)
)
)
server <- function(input, output, session) {
# Sample plot for the Data page
output$plot <- renderPlot({
plot(iris$Sepal.Length, iris$Sepal.Width,
col = iris$Species,
main = "Iris Dataset",
xlab = "Sepal Length",
ylab = "Sepal Width")
legend("topright", levels(iris$Species), col = 1:3, pch = 1)
})
}
shinyApp(ui, server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?