-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
68 lines (59 loc) · 1.97 KB
/
app.R
File metadata and controls
68 lines (59 loc) · 1.97 KB
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
library(shiny)
library(tidyverse)
library(bslib)
# Use cat data
proj_url = "https://raw.githubusercontent.com/VirginiaBee47/cat_log/refs/heads/main/cat_health.csv"
download.file(url = proj_url, destfile = "cat_health.csv")
kitty_data <- read_csv("cat_health.csv", skip = 1,
col_names = c("date",
"cat",
"attribute",
"value")) %>%
mutate(date = mdy(date))
# Define a custom theme using a Bootswatch theme (e.g., "cerulean")
my_theme <- bs_theme(bootswatch = "cerulean")
cards <- list(
card(
full_screen = TRUE,
card_header("Weight Over Time"),
plotOutput("weight_plot")
),
card(
full_screen = TRUE,
card_header("Injury Incidents"),
plotOutput("injury_plot")
)
)
ui <- page_navbar(
title = "Cat Health Tracker",
nav_spacer(),
nav_panel("Weight Over Time", cards[[1]]),
nav_panel("Injury Incidents", cards[[2]]),
nav_item(tags$a("Data Source.",
href = "https://raw.githubusercontent.com/VirginiaBee47/cat_log/refs/heads/main/cat_health.csv"))
)
# Define server logic required to draw the dashboard
server <- function(input, output) {
output$weight_plot <- renderPlot({
ggplot(kitty_data %>%
filter(attribute == 'weight'),
aes(x = date, y = value, color = cat)) +
geom_line() +
coord_cartesian(ylim = c(input$y_min, input$y_max)) +
theme_classic()
})
output$injury_plot <- renderPlot({
ggplot(kitty_data %>%
filter(attribute == 'injury'),
aes(x = date, y = value, color = cat)) +
geom_point(size = 4, shape = 3) +
coord_cartesian(ylim = c(0, 2)) +
theme_classic() +
theme(axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.line.y = element_blank(),
axis.ticks.y = element_blank())
})
}
# Run the application
shinyApp(ui = ui, server = server)