forked from MounaBelaid/shinylive-bslib-shiny-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
70 lines (65 loc) · 1.76 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
library(shiny)
library(ggplot2)
library(palmerpenguins)
library(DT)
library(dplyr)
library(bslib)
# UI
ui <- function() {
page_navbar(
title = "Penguin Dashboard",
sidebar = sidebar(
checkboxGroupInput("species_filter", "Filter by Species:",
choices = unique(penguins$species), selected = unique(penguins$species)
),
div(
style = "text-align:left; font-size: 15px",
strong("View Code "), a(icon("fab fa-github"), href = "https://github.com/MounaBelaid/shinylive-bslib-shiny-app", target = "_blank")
)
),
theme = bs_theme(
version = 5,
bootswatch = "materia"
),
nav_panel("Dashboard", layout_column_wrap(
card(
card_header("Penguin Distribution"),
plotOutput("penguin_plot"),
full_screen = TRUE
)
)),
nav_panel("Summary", layout_column_wrap(
card(
card_header("Penguin Summary"),
dataTableOutput("penguin_table"),
full_screen = TRUE
)
))
)
}
# Server
server <- function(input, output) {
# bs_themer()
# Filter penguins data based on user selection
filtered_data <- reactive({
req(input$species_filter)
if (is.null(input$species_filter)) {
return(penguins)
} else {
filter(penguins, species %in% input$species_filter)
}
})
# Render penguin distribution plot
output$penguin_plot <- renderPlot({
ggplot(filtered_data(), aes(x = species, fill = island)) +
geom_bar(position = "dodge") +
labs(title = "Penguin Distribution by Species and Island") +
theme_bw()
})
# Render penguin summary table based on filter
output$penguin_table <- renderDataTable({
datatable(filtered_data(), options = list(pageLength = 10))
})
}
# Run the application
shinyApp(ui, server)