Skip to content

Commit

Permalink
Added data imports to main.R, and created preliminary skeleton of the…
Browse files Browse the repository at this point in the history
… topmost module.
  • Loading branch information
AndrewDisher committed Dec 31, 2023
1 parent 119a13b commit ef82149
Showing 1 changed file with 113 additions and 15 deletions.
128 changes: 113 additions & 15 deletions app/main.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,123 @@
# -------------------------------------------------------------------------
# ---------------------------- Libraries/Packages -------------------------
# -------------------------------------------------------------------------

box::use(
shiny[bootstrapPage, div, moduleServer, NS, renderUI, tags, uiOutput],
sf[`st_crs<-`, st_read, st_transform],
shiny[moduleServer, NS, reactive, tagList, tags],
shiny.semantic[semanticPage]
)

#' @export
# -------------------------------------------------------------------------
# ---------------------------------- Modules ------------------------------
# -------------------------------------------------------------------------

# box::use(
# app/view[],

Check warning on line 16 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=16,col=5,[commented_code_linter] Commented code should be removed.
# app/logic[]

Check warning on line 17 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=17,col=5,[commented_code_linter] Commented code should be removed.
# )

# -------------------------------------------------------------------------
# ----------------------------- Helper Functions --------------------------
# -------------------------------------------------------------------------

card <- function(class, ...) {tags$div(class = class, ...)}

Check warning on line 24 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=24,col=30,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.

Check warning on line 24 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=24,col=59,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else.

custom_grid <- function(class, ...) {tags$div(class = class, ...)}

Check warning on line 26 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=26,col=37,[brace_linter] Opening curly braces should never go on their own line and should always be followed by a new line.

Check warning on line 26 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=26,col=66,[brace_linter] Closing curly-braces should always be on their own line, unless they are followed by an else.

# -------------------------------------------------------------------------
# ------------------------------ Data Imports -----------------------------
# -------------------------------------------------------------------------

# Ridership Data Sets
route_bar_chart_data <- read.csv(file = "data/ridership_data/route_bar_chart_data.csv")
stop_bar_chart_data <- read.csv(file = "data/ridership_data/stop_bar_chart_data.csv")

# Mapping Data Sets
bus_routes <- st_read("data/shape_data/mbta_bus_routes/bus_route_and_ridership.shp")
bus_stops <- st_read("data/shape_data/mbta_bus_stops/bus_stop_and_ridership.shp")

rapid_routes <- st_read("data/shape_data/mbta_rapid_routes/rapid_route_and_ridership.shp")
rapid_stops <- st_read("data/shape_data/mbta_rapid_stops/rapid_stop_and_ridership.shp")

ferry_routes <- st_read("data/shape_data/mbta_ferry_routes/ferry_route_and_ridership.shp")
ferry_stops <- st_read("data/shape_data/mbta_ferry_stops/ferry_stop_and_ridership.shp")

# Set the CRS code for each sf object
st_crs(bus_routes) <- 4326
st_crs(bus_stops) <- 4326

st_crs(rapid_routes) <- 4326
st_crs(rapid_stops) <- 4326

st_crs(ferry_routes) <- 4326
st_crs(ferry_stops) <- 4326

bus_routes <- st_transform(bus_routes, crs = 4326)

Check warning on line 56 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=56,col=51,[trailing_whitespace_linter] Trailing whitespace is superfluous.
bus_stops <- st_transform(bus_stops, crs = 4326)

Check warning on line 57 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=57,col=49,[trailing_whitespace_linter] Trailing whitespace is superfluous.

rapid_routes <- st_transform(rapid_routes, crs = 4326)

Check warning on line 59 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=59,col=55,[trailing_whitespace_linter] Trailing whitespace is superfluous.
rapid_stops <- st_transform(rapid_stops, crs = 4326)

Check warning on line 60 in app/main.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/main.R,line=60,col=53,[trailing_whitespace_linter] Trailing whitespace is superfluous.

ferry_routes <- st_transform(ferry_routes, crs = 4326)
ferry_stops <- st_transform(ferry_stops, crs = 4326)

# -------------------------------------------------------------------------
# ------------------------------ UI Function ------------------------------
# -------------------------------------------------------------------------

ui <- function(id) {
ns <- NS(id)
bootstrapPage(
uiOutput(ns("message"))
tagList(
semanticPage(
# -------------------------------
# ----- Layout for App Body -----
# -------------------------------
tags$div(class = "body-content-grid",
card(class = "map-card",
tags$div(class = "mbta-map",
"MBTA Map")
),
card(class = "plot-card",
tags$div(class = "mbta-route-bar-chart",
"Route Bar Chart")
),
card(class = "plot-card",
tags$div(class = "mbta-stop-bar-chart",
"Stop Bar Chart")
)
)
)
)
}

#' @export
# -------------------------------------------------------------------------
# ----------------------------- Server Function ---------------------------
# -------------------------------------------------------------------------

server <- function(id) {
moduleServer(id, function(input, output, session) {
output$message <- renderUI({
div(
style = "display: flex; justify-content: center; align-items: center; height: 100vh;",
tags$h1(
tags$a("Check out Rhino docs!", href = "https://appsilon.github.io/rhino/")
)
)
})
})
moduleServer(
id,
function(input, output, session) {
# ------------------------------
# ----- Reactive Data Sets -----
# ------------------------------

# Mapping Data Sets
shape_list <- reactive({
list(bus_routes = bus_routes, bus_stops = bus_stops,
rapid_routes = rapid_routes, rapid_stops = rapid_stops,
ferry_routes = ferry_routes, ferry_stops = ferry_stops)
})

# Bar Chart Data Sets
route_data <- reactive({ route_bar_chart_data })
stop_data <- reactive({ stop_bar_chart_data })

# ----------------------------------------------
# ----- Initialize Module Server Functions -----
# ----------------------------------------------

}
)
}

0 comments on commit ef82149

Please sign in to comment.