Skip to content

Commit

Permalink
it's good now :)
Browse files Browse the repository at this point in the history
  • Loading branch information
guslipkin committed Feb 15, 2024
1 parent a1bede3 commit 8f7ff2a
Show file tree
Hide file tree
Showing 35 changed files with 525 additions and 241 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.DS_Store
.Rproj.user
ClimbWith.Rcheck/
ClimbWith/rsconnect/shinyapps.io/guslipkin/ClimbWith.dcf
ClimbWith_0.0.0.9000.tar.gz
2 changes: 2 additions & 0 deletions TouchRocks/.Rbuildignore → ClimbWith/.Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ dev_history.R
^dev$
$run_dev.*
^.here$
^app\.R$
^rsconnect$
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions ClimbWith/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Package: ClimbWith
Title: Find Rock Climbing Gyms
Version: 0.0.0.9000
Authors@R: person('Gus', 'Lipkin', email = '[email protected]', role = c('cre', 'aut'))
Description: Look for rock climbing gyms based on features you want
License: What license is it under?
Imports:
config (>= 0.3.2),
golem (>= 0.4.1),
rlang,
shiny (>= 1.8.0),
DT,
bs4Dash,
dplyr,
glue,
htmltools,
janitor,
leaflet,
purrr,
readr,
shinyWidgets,
stringr,
tibble,
tidyr,
tidyselect,
waiter
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
1 change: 1 addition & 0 deletions TouchRocks/NAMESPACE → ClimbWith/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ importFrom(golem,add_resource_path)
importFrom(golem,bundle_resources)
importFrom(golem,favicon)
importFrom(golem,with_golem_options)
importFrom(rlang,.data)
importFrom(shiny,shinyApp)
7 changes: 7 additions & 0 deletions ClimbWith/R/ClimbWith-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @importFrom rlang .data
## usethis namespace: end
NULL
3 changes: 3 additions & 0 deletions ClimbWith/R/_disable_autoload.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disabling shiny autoload

# See ?shiny::loadSupport for more information
2 changes: 1 addition & 1 deletion TouchRocks/R/app_config.R → ClimbWith/R/app_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @noRd
app_sys <- function(...) {
system.file(..., package = "TouchRocks")
system.file(..., package = "ClimbWith")
}


Expand Down
75 changes: 75 additions & 0 deletions ClimbWith/R/app_server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#' The application server-side
#'
#' @param input,output,session Internal parameters for {shiny}.
#' DO NOT REMOVE.
#' @import shiny
#' @noRd
app_server <- function(input, output, session) {
shiny::updateActionButton(inputId = 'clear_filters', label = 'Clear Filters')
full_data <- .get_data()
dat <- shiny::reactiveVal(full_data)
output$map <-
dat() |>
.create_map() |>
leaflet::renderLeaflet()
output$table <-
dat() |>
.create_table() |>
DT::renderDT()

shiny::observe({
shinyWidgets::updateAwesomeCheckboxGroup(session, inputId = 'filter_climbing', selected = FALSE)
shinyWidgets::updateAwesomeCheckboxGroup(session, inputId = 'filter_fitness', selected = FALSE)
shinyWidgets::updateSliderTextInput(
session, inputId = 'filter_board_angle',
choices = c('Adjustable', as.character(seq(0L, 90L, by = 5L))),
selected = c('Adjustable', '90')
)
shinyWidgets::updateAwesomeCheckboxGroup(session, inputId = 'filter_generic_board', selected = FALSE)
shinyWidgets::updatePickerInput(session, inputId = 'filter_kilter_board_size', selected = FALSE)
shinyWidgets::updatePickerInput(session, inputId = 'filter_tension1_board_size', selected = FALSE)
shinyWidgets::updatePickerInput(session, inputId = 'filter_tension1_board_set', selected = FALSE)
shinyWidgets::updatePickerInput(session, inputId = 'filter_tension2_board_size', selected = FALSE)
shinyWidgets::updatePickerInput(session, inputId = 'filter_tension2_board_set', selected = FALSE)
shinyWidgets::updatePickerInput(session, inputId = 'filter_moonboard_board_set', selected = FALSE)
}) |>
shiny::bindEvent(input$clear_filters, ignoreNULL = TRUE, ignoreInit = FALSE)

shiny::observe({
dt <- if (is.null(input$table_rows_selected)) dat() else dat()[input$table_rows_selected,]
if (nrow(dt) == 0) {
shinyWidgets::show_alert(
title = 'No Matches',
text = 'No gyms match your filters',
type = 'warning'
)
}
leaflet::leafletProxy('map', data = dt) |>
.add_markers_and_fit(dt)
}) |>
shiny::bindEvent(dat(), input$table_rows_selected, ignoreNULL = FALSE, ignoreInit = TRUE)

shiny::observe({
full_data |>
.filter_climbing(input$filter_climbing) |>
.filter_fitness(input$filter_fitness) |>
.filter_board_angle(input$filter_board_angle) |>
.filter_generic_board(input$filter_generic_board) |>
.filter_sictb(
input$filter_kilter_board_size,
input$filter_tension1_board_size, input$filter_tension1_board_set,
input$filter_tension2_board_size, input$filter_tension2_board_set,
input$filter_moonboard_board_set
) |>
dat()
}) |>
shiny::bindEvent(
input$filter_climbing, input$filter_fitness,
input$filter_board_angle, input$filter_generic_board,
input$filter_kilter_board_size,
input$filter_tension1_board_size, input$filter_tension1_board_set,
input$filter_tension2_board_size, input$filter_tension2_board_set,
input$filter_moonboard_board_set,
ignoreNULL = FALSE, ignoreInit = TRUE
)
}
57 changes: 43 additions & 14 deletions TouchRocks/R/app_ui.R → ClimbWith/R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
#' @noRd
app_ui <- function(request) {
bs4Dash::dashboardPage(
scrollToTop = TRUE,
preloader = list(html = shiny::tagList(waiter::spin_1(), "Loading ..."), color = "#3c8dbc"),
header = bs4Dash::bs4DashNavbar(
status = 'primary',
title = bs4Dash::dashboardBrand(
title = 'Touch Rocks',
title = 'ClimbWith',
color = 'primary'
)
),
Expand All @@ -18,21 +21,32 @@ app_ui <- function(request) {
body = bs4Dash::dashboardBody(
bs4Dash::box(
title = 'Map',
color = 'secondary',
width = 12,
maximizable = TRUE,
status = 'secondary',
solidHeader = TRUE,
# maximizable = TRUE,
leaflet::leafletOutput('map')
),
bs4Dash::box(
title = 'Filters',
width = 12,
id = 'box_filter',
width = 12,
status = 'secondary',
solidHeader = TRUE,
dropdownMenu = bs4Dash::actionButton(
inputId = 'clear_filters',
label = NULL,
status = 'warning',
size = 'xs'
),
shiny::fluidRow(
shiny::column(
width = 6,
bs4Dash::box(
title = 'Climbing',
width = 12,
status = 'info',
solidHeader = TRUE,
collapsible = FALSE,
shinyWidgets::awesomeCheckboxGroup(
inputId = 'filter_climbing',
Expand All @@ -46,6 +60,8 @@ app_ui <- function(request) {
bs4Dash::box(
title = 'Fitness',
width = 12,
status = 'info',
solidHeader = TRUE,
collapsible = FALSE,
shinyWidgets::awesomeCheckboxGroup(
inputId = 'filter_fitness',
Expand All @@ -61,19 +77,21 @@ app_ui <- function(request) {
bs4Dash::box(
title = 'Training Boards',
width = 12,
collapsible = FALSE,
status = 'info',
solidHeader = TRUE,
collapsible = TRUE,
shiny::fluidRow(
shiny::column(
width = 6,
bs4Dash::box(
title = 'Board Angle',
width = 12,
collapsible = FALSE,
shiny::tags$p('An angle of 0° is a vertical wall and 90° is a horizontal wall.'),
shiny::tags$p('An angle of 0\u00B0 is a vertical wall and 90\u00B0 is a horizontal wall.'),
shinyWidgets::sliderTextInput(
inputId = 'filter_board_angle',
label = NULL,
choices = c('Adjustable', seq(0L, 90L, by = 5L)),
choices = c('Adjustable', as.character(seq(0L, 90L, by = 5L))),
selected = c('Adjustable', '90'),
force_edges = TRUE,
grid = TRUE
Expand Down Expand Up @@ -104,7 +122,7 @@ app_ui <- function(request) {
shinyWidgets::pickerInput(
inputId = 'filter_kilter_board_size',
label = 'Size:',
choices = c('7x10 (Home)', '8x12', '12x12', '16x12'),
choices = .get_kilter_size(),
multiple = TRUE,
options = shinyWidgets::pickerOptions(
actionsBox = TRUE,
Expand All @@ -125,7 +143,7 @@ app_ui <- function(request) {
shinyWidgets::pickerInput(
inputId = 'filter_tension1_board_size',
label = 'Size:',
choices = c('8x10', '10x12'),
choices = .get_tension1_size(),
multiple = TRUE,
options = shinyWidgets::pickerOptions(
actionsBox = TRUE,
Expand All @@ -140,7 +158,7 @@ app_ui <- function(request) {
shinyWidgets::pickerInput(
inputId = 'filter_tension1_board_set',
label = 'Set:',
choices = c('A', 'B', 'C'),
choices = .get_tension1_set(),
multiple = TRUE,
options = shinyWidgets::pickerOptions(
actionsBox = TRUE,
Expand All @@ -163,7 +181,7 @@ app_ui <- function(request) {
shinyWidgets::pickerInput(
inputId = 'filter_tension2_board_size',
label = 'Size:',
choices = c('8x10', '12x10', '8x12', '12x12'),
choices = .get_tension2_size(),
multiple = TRUE,
options = shinyWidgets::pickerOptions(
actionsBox = TRUE,
Expand All @@ -178,7 +196,7 @@ app_ui <- function(request) {
shinyWidgets::pickerInput(
inputId = 'filter_tension2_board_set',
label = 'Set:',
choices = c('Spray', 'Mirror'),
choices = .get_tension2_set(),
multiple = TRUE,
options = shinyWidgets::pickerOptions(
actionsBox = TRUE,
Expand All @@ -198,7 +216,7 @@ app_ui <- function(request) {
shinyWidgets::pickerInput(
inputId = 'filter_moonboard_board_set',
label = 'Set:',
choices = c('2016', '2017', '2019', '2024', 'Mini 2020'),
choices = .get_moonboard_set(),
multiple = TRUE,
options = shinyWidgets::pickerOptions(
actionsBox = TRUE,
Expand All @@ -216,10 +234,21 @@ app_ui <- function(request) {
title = 'Table',
width = 12,
id = 'box_table',
status = 'secondary',
solidHeader = TRUE,
DT::DTOutput('table')
),
golem_add_external_resources()
)
# footer = bs4Dash::dashboardFooter(
# left = shiny::div(
# 'Jump To: ',
# shinyWidgets::actionBttn(inputId = 'jump_to_map', label = 'Map', style = 'material-flat'),
# shinyWidgets::actionBttn(inputId = 'jump_to_filters', label = 'Filters', style = 'material-flat'),
# shinyWidgets::actionBttn(inputId = 'jump_to_table', label = 'Table', style = 'material-flat')
# ),
# fixed = TRUE
# )
)
}

Expand All @@ -241,7 +270,7 @@ golem_add_external_resources <- function() {
favicon(),
bundle_resources(
path = app_sys("app/www"),
app_title = "TouchRocks"
app_title = "ClimbWith"
)
# Add here other external resources
# for example, you can add shinyalert::useShinyalert()
Expand Down
File renamed without changes.
75 changes: 75 additions & 0 deletions ClimbWith/R/utils_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#' data
#'
#' @description A utils function
#'
#' @return The return value, if any, from executing the utility.
#'
#' @noRd
.get_data <- function() {
readr::read_csv('data/data.csv', show_col_types = FALSE) |>
janitor::clean_names() |>
dplyr::mutate(
dplyr::across(
tidyselect::matches('spray_wall|board_'), # fix training boards
\(x) {
dplyr::case_when(
x == 'Unknown' ~ '-2',
x == 'Adjustable' ~ '-1',
.default = as.character(x)
) |>
as.integer()
}
),
dplyr::across(
tidyselect::everything(),
\(x) {
if (!all(unique(x) %in% c('Yes', 'No', ''))) return(x)
dplyr::case_match(x, 'Yes' ~ TRUE, 'No' ~ FALSE, '' ~ NA)
}
),
'lat' = purrr::map_dbl(.data$google_maps_link, \(x) {
stringr::str_match(x, '/@(-?\\d+\\.\\d+),')[1,2] |>
as.numeric()
}),
'lon' = purrr::map_dbl(.data$google_maps_link, \(x) {
stringr::str_match(x, ',(-?\\d+\\.\\d+),\\d+')[1,2] |>
as.numeric()
})
) |>
dplyr::mutate(
'full_name' = .data$gym_name,
'name' = janitor::make_clean_names(.data$gym_name),
.before = 1
) |>
dplyr::select(-'gym_name') |>
dplyr::arrange(.data$full_name) -> dt
}

.table_lookup <- function(lookup = TRUE) {
c(
"kilter_board_7x10_home" = 'Kilter 7x10 (Home)',
"kilter_board_8x12" = 'Kilter 8x12',
"kilter_board_12x12" = 'Kilter 12x12',
"kilter_board_16x12" = 'Kilter 16x12',
"tension_board_tension_1_8x10_set_a" = 'Tension 1 8x10 Set A',
"tension_board_tension_1_8x10_set_b" = 'Tension 1 8x10 Set B',
"tension_board_tension_1_8x10_set_c" = 'Tension 1 8x10 Set C',
"tension_board_tension_1_8x12_set_a" = 'Tension 1 8x12 Set A',
"tension_board_tension_1_8x12_set_b" = 'Tension 1 8x12 Set B',
"tension_board_tension_1_8x12_set_c" = 'Tension 1 8x12 Set C',
"tension_board_tension_2_8x10_spray" = 'Tension 2 8x10 Spray',
"tension_board_tension_2_8x10_mirror" = 'Tension 2 8x10 Mirror',
"tension_board_tension_2_8x12_spray" = 'Tension 2 8x12 Spray',
"tension_board_tension_2_8x12_mirror" = 'Tension 2 8x12 Mirror',
"tension_board_tension_2_12x10_spray" = 'Tension 2 12x10 Spray',
"tension_board_tension_2_12x10_mirror" = 'Tension 2 12x10 Mirror',
"tension_board_tension_2_12x12_spray" = 'Tension 2 12x12 Spray',
"tension_board_tension_2_12x12_mirror" = 'Tension 2 12x12 Mirror',
"moon_board_moon_board_2016" = 'MoonBoard 2016',
"moon_board_moon_board_2017" = 'MoonBoard 2017',
"moon_board_moon_board_2019" = 'MoonBoard 2019',
"moon_board_moon_board_2024" = 'MoonBoard 2024',
"moon_board_moon_board_mini_2020" = 'MoonBoard Mini 2020',
"spray_wall" = "Spray Wall"
)[lookup]
}
Loading

0 comments on commit 8f7ff2a

Please sign in to comment.