├── .Rbuildignore ├── .gitignore ├── CODE_OF_CONDUCT.md ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R ├── app_config.R ├── app_server.R ├── app_ui.R ├── datasets.R ├── fct_nav.R ├── globals.R ├── golem_utils_server.R ├── golem_utils_ui.R ├── mod_about.R ├── mod_dataviz.R ├── mod_dataviz_utils_ui.R ├── mod_raw.R ├── run_app.R └── utils-pipe.R ├── README.Rmd ├── README.md ├── app.R ├── data-raw └── big_epa_cars.R ├── data ├── big_epa_cars.rda └── datalist ├── dev ├── 01_start.R ├── 02_dev.R ├── 03_deploy.R └── run_dev.R ├── inst ├── .DS_Store ├── app │ ├── .DS_Store │ └── www │ │ ├── about.md │ │ ├── custom.css │ │ ├── favicon.ico │ │ ├── home.html │ │ ├── home.md │ │ ├── script.js │ │ └── tech.md └── golem-config.yml ├── man ├── big_epa_cars.Rd ├── mod_about.Rd ├── mod_dataviz.Rd ├── mod_raw.Rd ├── pipe.Rd └── run_app.Rd ├── manifest.json ├── tests ├── testthat.R └── testthat │ └── test-golem-recommended.R └── tidytuesday201942.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^CODE_OF_CONDUCT\.md$ 4 | ^LICENSE\.md$ 5 | ^README\.Rmd$ 6 | ^app\.R$ 7 | ^data-raw$ 8 | ^dev$ 9 | ^manifest\.json$ 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who 4 | contribute through reporting issues, posting feature requests, updating documentation, 5 | submitting pull requests or patches, and other activities. 6 | 7 | We are committed to making participation in this project a harassment-free experience for 8 | everyone, regardless of level of experience, gender, gender identity and expression, 9 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 10 | 11 | Examples of unacceptable behavior by participants include the use of sexual language or 12 | imagery, derogatory comments or personal attacks, trolling, public or private harassment, 13 | insults, or other unprofessional conduct. 14 | 15 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 16 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 17 | Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed 18 | from the project team. 19 | 20 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 21 | opening an issue or contacting one or more of the project maintainers. 22 | 23 | This Code of Conduct is adapted from the Contributor Covenant 24 | (https://www.contributor-covenant.org), version 1.0.0, available at 25 | https://contributor-covenant.org/version/1/0/0/. 26 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: tidytuesday201942 2 | Title: A golem App for Tidy Tuesday 3 | Version: 0.0.0.9000 4 | Authors@R: 5 | person(given = "Colin", 6 | family = "Fay", 7 | role = c("cre", "aut"), 8 | email = "contact@colinfay.me") 9 | Description: A golem App for Tidy Tuesday. 10 | License: MIT + file LICENSE 11 | URL: http://www.github.com/ColinFay/tidytuesday201942 12 | BugReports: 13 | http://www.github.com/ColinFay/tidytuesday201942/issues 14 | Depends: 15 | R (>= 2.10) 16 | Imports: 17 | colourvalues, 18 | dplyr, 19 | ggplot2, 20 | glue, 21 | golem, 22 | htmltools, 23 | magrittr, 24 | purrr, 25 | rlang, 26 | shiny, 27 | styler, 28 | withr, 29 | markdown 30 | Suggests: 31 | pkgload, 32 | processx, 33 | testthat 34 | Encoding: UTF-8 35 | LazyData: true 36 | RoxygenNote: 7.2.3 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2019 2 | COPYRIGHT HOLDER: Colin Fay 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2019 Colin Fay 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(mod_about_server) 5 | export(mod_about_ui) 6 | export(mod_dataviz_server) 7 | export(mod_dataviz_ui) 8 | export(mod_raw_server) 9 | export(mod_raw_ui) 10 | export(run_app) 11 | import(ggplot2) 12 | import(golem) 13 | import(shiny) 14 | importFrom(colourvalues,color_values) 15 | importFrom(dplyr,pull) 16 | importFrom(glue,glue) 17 | importFrom(golem,with_golem_options) 18 | importFrom(htmltools,HTML) 19 | importFrom(htmltools,tagAppendAttributes) 20 | importFrom(htmltools,tagList) 21 | importFrom(htmltools,tags) 22 | importFrom(magrittr,"%>%") 23 | importFrom(rlang,sym) 24 | importFrom(shiny,NS) 25 | importFrom(shiny,column) 26 | importFrom(shiny,includeMarkdown) 27 | importFrom(shiny,shinyApp) 28 | importFrom(shiny,tagList) 29 | importFrom(styler,style_text) 30 | importFrom(withr,with_package) 31 | -------------------------------------------------------------------------------- /R/app_config.R: -------------------------------------------------------------------------------- 1 | #' Access files in the current app 2 | #' 3 | #' NOTE: If you manually change your package name in the DESCRIPTION, 4 | #' don't forget to change it here too, and in the config file. 5 | #' For a safer name change mechanism, use the `golem::set_golem_name()` function. 6 | #' 7 | #' @param ... character vectors, specifying subdirectory and file(s) 8 | #' within your package. The default, none, returns the root of the app. 9 | #' 10 | #' @noRd 11 | app_sys <- function(...) { 12 | system.file(..., package = "tidytuesday201942") 13 | } 14 | 15 | 16 | #' Read App Config 17 | #' 18 | #' @param value Value to retrieve from the config file. 19 | #' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE. 20 | #' If unset, "default". 21 | #' @param use_parent Logical, scan the parent directory for config file. 22 | #' @param file Location of the config file 23 | #' 24 | #' @noRd 25 | get_golem_config <- function( 26 | value, 27 | config = Sys.getenv( 28 | "GOLEM_CONFIG_ACTIVE", 29 | Sys.getenv( 30 | "R_CONFIG_ACTIVE", 31 | "default" 32 | ) 33 | ), 34 | use_parent = TRUE, 35 | # Modify this if your config file is somewhere else 36 | file = app_sys("golem-config.yml") 37 | ) { 38 | config::get( 39 | value = value, 40 | config = config, 41 | file = file, 42 | use_parent = use_parent 43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /R/app_server.R: -------------------------------------------------------------------------------- 1 | #' @import shiny 2 | app_server <- function(input, output,session) { 3 | #callModule(mod_raw_server, "raw_ui_1") 4 | callModule(mod_dataviz_server, "dataviz_ui_1", type = "point") 5 | callModule(mod_dataviz_server, "dataviz_ui_2", type = "hist") 6 | callModule(mod_dataviz_server, "dataviz_ui_3", type = "boxplot") 7 | callModule(mod_dataviz_server, "dataviz_ui_4", type = "bar") 8 | } 9 | -------------------------------------------------------------------------------- /R/app_ui.R: -------------------------------------------------------------------------------- 1 | #' @import shiny 2 | app_ui <- function() { 3 | tagList( 4 | # Leave this function for adding external resources 5 | golem_add_external_resources(), 6 | # List the first level UI elements here 7 | tagList( 8 | nav_( 9 | "#TidyTuesday 2019-10-15", 10 | c( 11 | "raw_data" = "dataset", 12 | "geom_point" = "geom_point", 13 | "geom_hist" = "geom_hist", 14 | "geom_boxplot" = "geom_boxplot", 15 | "geom_bar" = "geom_bar", 16 | "about" = "About" 17 | ) 18 | ) 19 | , 20 | tags$div( 21 | class="container", 22 | fluidRow( 23 | id = "raw_data", mod_raw_ui("raw_ui_1") 24 | ) %>% tagAppendAttributes( 25 | style = "display:none" 26 | ), 27 | fluidRow( 28 | id = "geom_point", mod_dataviz_ui("dataviz_ui_1", "point") 29 | ) %>% tagAppendAttributes( 30 | style = "display:none" 31 | ), 32 | fluidRow( 33 | id = "geom_hist", mod_dataviz_ui("dataviz_ui_2", "hist") 34 | ) %>% tagAppendAttributes( 35 | style = "display:none" 36 | ), 37 | fluidRow( 38 | id = "geom_boxplot", mod_dataviz_ui("dataviz_ui_3", "boxplot") 39 | ) %>% tagAppendAttributes( 40 | style = "display:none" 41 | ), 42 | fluidRow( 43 | id = "geom_bar", mod_dataviz_ui("dataviz_ui_4", "bar") 44 | ) %>% tagAppendAttributes( 45 | style = "display:none" 46 | ), 47 | fluidRow( 48 | id = "about", mod_about_ui("about_ui_1") 49 | ) %>% tagAppendAttributes( 50 | style = "display:none" 51 | ) 52 | ) 53 | 54 | ) 55 | ) 56 | } 57 | 58 | #' @import shiny 59 | #' @import golem 60 | golem_add_external_resources <- function(){ 61 | 62 | addResourcePath( 63 | 'www', system.file('app/www', package = 'tidytuesday201942') 64 | ) 65 | 66 | tags$head( 67 | golem::activate_js(), 68 | golem::favicon(), 69 | tags$title("TidyTuesday 2019 - 42"), 70 | # Add here all the external resources 71 | # If you have a custom.css in the inst/app/www 72 | # Or for example, you can add shinyalert::useShinyalert() here 73 | tags$link( 74 | rel="stylesheet", 75 | type="text/css", 76 | href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css", 77 | integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T", 78 | crossorigin="anonymous" 79 | ), 80 | tags$script( 81 | src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js", 82 | integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM", 83 | crossorigin="anonymous" 84 | ), 85 | tags$link( 86 | rel="stylesheet", 87 | type="text/css", 88 | href="www/custom.css" 89 | ), 90 | tags$script(src="www/script.js") 91 | ) 92 | } 93 | -------------------------------------------------------------------------------- /R/datasets.R: -------------------------------------------------------------------------------- 1 | #' big_epa_cars 2 | #' 3 | #' Dataset from tidytuesday: rfordatascience/tidytuesday 4 | #' @format Tibble with 41,804 features and 83 fields 5 | "big_epa_cars" -------------------------------------------------------------------------------- /R/fct_nav.R: -------------------------------------------------------------------------------- 1 | #' @importFrom htmltools tags 2 | nav_ <- function(name, x){ 3 | tags$nav( 4 | class="navbar navbar-expand-lg fixed-top ", 5 | tags$p( 6 | name 7 | ), 8 | # For portait mode 9 | tags$button( 10 | class="navbar-toggler", 11 | type="button", 12 | `data-toggle`="collapse", 13 | `data-target`="#menu", 14 | `aria-controls`="menu", 15 | `aria-expanded`="false" , 16 | `aria-label`="Toggle navigation", 17 | tags$div( 18 | class="navbar-toggler-icon", 19 | HTML('') 20 | ) 21 | ), 22 | tags$div( 23 | class="collapse navbar-collapse", 24 | id="menu", 25 | tags$ul( 26 | class="navbar-nav mr-4", 27 | tagList( 28 | purrr::imap( 29 | x, nav_item 30 | ) 31 | ) 32 | ) 33 | ) 34 | ) %>% tags$div(class = "plpl") 35 | } 36 | 37 | #' @importFrom htmltools tags 38 | #' @importFrom glue glue 39 | nav_item <- function(label, id){ 40 | tags$li( 41 | class="nav-item", 42 | tags$a( 43 | class="nav-link", 44 | `data-value` = label, 45 | onclick = glue( 46 | '$( "a.nav-link" ).removeClass("active"); 47 | $( this ).addClass("active"); 48 | $( ".row" ).hide(); 49 | $( "#{id}" ).show(); 50 | $( "#{id}" ).trigger("show"); 51 | $( "#{id}" ).trigger("shown")' 52 | ), 53 | label 54 | ) 55 | ) 56 | } -------------------------------------------------------------------------------- /R/globals.R: -------------------------------------------------------------------------------- 1 | globalVariables( 2 | c( 3 | "big_epa_cars" 4 | ) 5 | ) -------------------------------------------------------------------------------- /R/golem_utils_server.R: -------------------------------------------------------------------------------- 1 | # Inverted versions of in, is.null and is.na 2 | `%not_in%` <- Negate(`%in%`) 3 | 4 | not_null <- Negate(is.null) 5 | 6 | not_na <- Negate(is.na) 7 | 8 | # Removes the null from a vector 9 | drop_nulls <- function(x){ 10 | x[!sapply(x, is.null)] 11 | } 12 | 13 | # If x is null, return y, otherwise return x 14 | "%||%" <- function(x, y){ 15 | if (is.null(x)) { 16 | y 17 | } else { 18 | x 19 | } 20 | } 21 | # If x is NA, return y, otherwise return x 22 | "%|NA|%" <- function(x, y){ 23 | if (is.na(x)) { 24 | y 25 | } else { 26 | x 27 | } 28 | } 29 | 30 | # typing reactiveValues is too long 31 | rv <- shiny::reactiveValues 32 | rvtl <- shiny::reactiveValuesToList -------------------------------------------------------------------------------- /R/golem_utils_ui.R: -------------------------------------------------------------------------------- 1 | # Turn an R list into an HTML list 2 | # 3 | # @param list An R list 4 | # @param class a class for the list 5 | # @return an HTML list 6 | # @examples 7 | # list_to_li(c("a","b")) 8 | # 9 | #' @importFrom htmltools tags tagAppendAttributes tagList 10 | list_to_li <- function(list, class = NULL){ 11 | if (is.null(class)){ 12 | tagList(lapply(list, tags$li)) 13 | } else { 14 | res <- lapply(list, tags$li) 15 | res <- lapply(res, function(x) tagAppendAttributes(x, class = class)) 16 | tagList(res) 17 | } 18 | 19 | } 20 | 21 | #' @importFrom htmltools tags tagAppendAttributes tagList 22 | list_to_p <- function(list, class = NULL){ 23 | if (is.null(class)){ 24 | tagList(lapply(list, tags$p)) 25 | } else { 26 | res <- lapply(list, tags$p) 27 | res <- lapply(res, function(x) tagAppendAttributes(x, class = class)) 28 | tagList(res) 29 | } 30 | 31 | } 32 | 33 | #' @importFrom glue glue 34 | #' @importFrom htmltools tags tagAppendAttributes tagList 35 | named_to_li <- function(list, class = NULL){ 36 | if(is.null(class)){ 37 | res <- mapply( 38 | function(x, y){ 39 | tags$li(HTML(glue("{y}: {x}"))) 40 | }, 41 | list, names(list), SIMPLIFY = FALSE) 42 | #res <- lapply(res, HTML) 43 | tagList(res) 44 | } else { 45 | res <- mapply( 46 | function(x, y){ 47 | tags$li(HTML(glue("{y}: {x}"))) 48 | }, 49 | list, names(list), SIMPLIFY = FALSE) 50 | res <- lapply(res, function(x) tagAppendAttributes(x, class = class)) 51 | tagList(res) 52 | } 53 | } 54 | 55 | # Remove a tag attribute 56 | # 57 | # @param tag the tag 58 | # @param ... the attributes to remove 59 | # 60 | # @return a new tag 61 | # @export 62 | # 63 | # @examples 64 | # a <- shiny::tags$p(src = "plop", "pouet") 65 | # tagRemoveAttributes(a, "src") 66 | tagRemoveAttributes <- function(tag, ...) { 67 | attrs <- as.character(list(...)) 68 | for (i in seq_along(attrs)) { 69 | tag$attribs[[ attrs[i] ]] <- NULL 70 | } 71 | tag 72 | } 73 | 74 | # Hide or display a tag 75 | # @param tag the tag 76 | # @return a tag 77 | # @examples 78 | # ## Hide 79 | # a <- shiny::tags$p(src = "plop", "pouet") 80 | # undisplay(a) 81 | # b <- shiny::actionButton("go_filter", "go") 82 | # undisplay(b) 83 | 84 | #' @importFrom htmltools tagList 85 | undisplay <- function(tag) { 86 | # if not already hidden 87 | if (!is.null(tag$attribs$style) && !grepl("display:\\s+none", tag$attribs$style)) { 88 | tag$attribs$style <- paste("display: none;", tag$attribs$style) 89 | } else { 90 | tag$attribs$style <- "display: none;" 91 | } 92 | tag 93 | } 94 | 95 | #' @importFrom htmltools tagList 96 | display <- function(tag) { 97 | if (!is.null(tag$attribs$style) && grepl("display:\\s+none", tag$attribs$style)) { 98 | tag$attribs$style <- gsub("(\\s)*display:(\\s)*none(\\s)*(;)*(\\s)*", "", tag$attribs$style) 99 | } 100 | tag 101 | } 102 | 103 | # Hide an elements by calling jquery hide on it 104 | #' @importFrom htmltools tags 105 | jq_hide <- function(id) { 106 | tags$script(sprintf("$('#%s').hide()", id)) 107 | } 108 | 109 | # Add a red star at the end of the text 110 | # 111 | # Adds a red star at the end of the text 112 | # (for example for indicating mandatory fields). 113 | # 114 | # @param text the HTLM text to put before the red star 115 | # 116 | # @return an html element 117 | # 118 | # @examples 119 | # with_red_star("Enter your name here") 120 | # 121 | #' @importFrom htmltools tags HTML 122 | with_red_star <- function(text) { 123 | htmltools::tags$span( 124 | HTML( 125 | paste0( 126 | text, 127 | htmltools::tags$span( 128 | style = "color:red", "*" 129 | ) 130 | ) 131 | ) 132 | ) 133 | } 134 | 135 | 136 | 137 | # Repeat tags$br 138 | # 139 | # @param times the number of br to return 140 | # 141 | # @return the number of br specified in times 142 | # @export 143 | # 144 | # @examples 145 | # rep_br(5) 146 | # 147 | #' @importFrom htmltools HTML 148 | rep_br <- function(times = 1) { 149 | HTML(rep("
", times = times)) 150 | } 151 | 152 | # Create an url 153 | # 154 | # @param url the URL 155 | # @param text the text to display 156 | # 157 | # @return an a tag 158 | # @export 159 | # 160 | # @examples 161 | # enurl("https://www.thinkr.fr", "ThinkR") 162 | enurl <- function(url, text){ 163 | tags$a(href = url, text) 164 | } 165 | 166 | 167 | # Columns wrappers 168 | # 169 | # These are convenient wrappers around 170 | # `column(12, ...)`, `column(6, ...)`, `column(4, ...)`... 171 | # 172 | # @export 173 | # @rdname columns 174 | #' @importFrom shiny column 175 | col_12 <- function(...){ 176 | column(12, ...) 177 | } 178 | 179 | #' @importFrom shiny column 180 | col_10 <- function(...){ 181 | column(10, ...) 182 | } 183 | 184 | #' @importFrom shiny column 185 | col_8 <- function(...){ 186 | column(8, ...) 187 | } 188 | 189 | #' @importFrom shiny column 190 | col_6 <- function(...){ 191 | column(6, ...) 192 | } 193 | 194 | #' @importFrom shiny column 195 | col_4 <- function(...){ 196 | column(4, ...) 197 | } 198 | 199 | #' @importFrom shiny column 200 | col_3 <- function(...){ 201 | column(3, ...) 202 | } 203 | 204 | #' @importFrom shiny column 205 | col_2 <- function(...){ 206 | column(2, ...) 207 | } 208 | 209 | #' @importFrom shiny column 210 | col_1 <- function(...){ 211 | column(1, ...) 212 | } 213 | 214 | -------------------------------------------------------------------------------- /R/mod_about.R: -------------------------------------------------------------------------------- 1 | # Module UI 2 | 3 | #' @title mod_about_ui and mod_about_server 4 | #' @description A shiny Module. 5 | #' 6 | #' @param id shiny id 7 | #' @param input internal 8 | #' @param output internal 9 | #' @param session internal 10 | #' 11 | #' @rdname mod_about 12 | #' 13 | #' @keywords internal 14 | #' @export 15 | #' @importFrom shiny NS tagList includeMarkdown 16 | mod_about_ui <- function(id){ 17 | ns <- NS(id) 18 | tagList( 19 | col_6( 20 | includeMarkdown( 21 | system.file("app/www/about.md", package = "tidytuesday201942") 22 | ) 23 | ), 24 | col_6( 25 | includeMarkdown( 26 | system.file("app/www/tech.md", package = "tidytuesday201942") 27 | ) 28 | ) 29 | ) 30 | } 31 | 32 | # Module Server 33 | 34 | #' @rdname mod_about 35 | #' @export 36 | #' @keywords internal 37 | 38 | mod_about_server <- function(input, output, session){ 39 | ns <- session$ns 40 | } 41 | 42 | ## To be copied in the UI 43 | # 44 | 45 | ## To be copied in the server 46 | # callModule(mod_about_server, "about_ui_1") 47 | 48 | -------------------------------------------------------------------------------- /R/mod_dataviz.R: -------------------------------------------------------------------------------- 1 | # Module UI 2 | 3 | #' @title mod_dataviz_ui and mod_dataviz_server 4 | #' @description A shiny Module. 5 | #' 6 | #' @param id shiny id 7 | #' @param input internal 8 | #' @param output internal 9 | #' @param session internal 10 | #' 11 | #' @rdname mod_dataviz 12 | #' 13 | #' @keywords internal 14 | #' @export 15 | #' @import shiny 16 | #' @importFrom htmltools tags 17 | mod_dataviz_ui <- function(id, type = c("point", "hist", "boxplot", "bar")){ 18 | ns <- NS(id) 19 | tagList( 20 | col_3( 21 | h4( 22 | sprintf( 23 | "Create a geom_%s", type 24 | ) 25 | ), 26 | if (type == "boxplot" | type =="bar") { 27 | selectInput( 28 | ns("x"), 29 | "x", 30 | choices = names_that_are(c("logical", "character")) 31 | ) 32 | } else { 33 | selectInput( 34 | ns("x"), 35 | "x", 36 | choices = names_that_are("numeric") 37 | ) 38 | } 39 | , 40 | if (type == "point" | type == "boxplot"){ 41 | selectInput( 42 | ns("y"), 43 | "y", 44 | choices = names_that_are("numeric") 45 | ) 46 | } else if (type == "hist") { 47 | numericInput( 48 | ns("bins"), 49 | "bins", 50 | 30, 51 | 1, 52 | 150, 53 | 1 54 | ) 55 | }, 56 | if (type != "boxplot" & type != "bar"){ 57 | selectInput( 58 | ns("color"), 59 | "color", 60 | choices = names_that_are(c("logical", "character")) 61 | ) 62 | } else if (type == "bar"){ 63 | selectInput( 64 | ns("fill"), 65 | "fill", 66 | choices = names_that_are(c("logical", "character")) 67 | ) 68 | }, 69 | if (type == "bar"){ 70 | checkboxInput( 71 | ns("coord_flip"), 72 | "coord_flip" 73 | ) 74 | }, 75 | selectInput( 76 | ns("theme"), 77 | "theme", 78 | choices = themess() 79 | ), 80 | if (type != "boxplot"){ 81 | selectInput( 82 | ns("palette"), 83 | "palette", 84 | choices = colourvalues::colour_palettes() 85 | ) 86 | }, 87 | textInput( 88 | ns("title"), 89 | "Title", 90 | value = "" 91 | ), 92 | tags$blockquote( 93 | "Note that the rendering is not reactive, you'll need to click on the 'Render Plot' button to see your graph." 94 | ) 95 | ), 96 | column( 97 | 9, 98 | col_12( 99 | actionButton( 100 | ns("go"), 101 | "Render Plot", icon = icon("arrow-down") 102 | ) %>% 103 | tags$div(align = "center", style = "padding-left:2em") 104 | ), 105 | HTML(" ") 106 | , 107 | col_12( 108 | plotOutput(ns("plot")) %>% 109 | tagAppendAttributes( 110 | onclick = sprintf( 111 | "Shiny.setInputValue('%s', true, {priority : 'event'})", 112 | ns("show") 113 | ) 114 | ) 115 | ) , 116 | HTML(" "), 117 | col_12( 118 | tags$p( 119 | "Click on the graph to see the code" 120 | ) %>% 121 | tags$div(align = "center") 122 | ), 123 | col_12( 124 | downloadButton(ns("dl")) %>% 125 | tags$div(align = "right") 126 | ) 127 | ) 128 | ) 129 | } 130 | 131 | # Module Server 132 | 133 | #' @rdname mod_dataviz 134 | #' @export 135 | #' @import ggplot2 136 | #' @import shiny 137 | #' @importFrom colourvalues color_values 138 | #' @importFrom rlang sym 139 | #' @importFrom dplyr pull 140 | #' @importFrom styler style_text 141 | #' @keywords internal 142 | 143 | mod_dataviz_server <- function(input, output, session, type){ 144 | ns <- session$ns 145 | 146 | r <- rv( 147 | plot = ggplot(big_epa_cars), 148 | code = "ggplot(big_epa_cars)" 149 | ) 150 | 151 | observeEvent( input$go , { 152 | 153 | x <- rlang::sym(input$x) 154 | 155 | if (type == "point"){ 156 | y <- sym(input$y) 157 | color <- sym(input$color) 158 | r$plot <- ggplot(big_epa_cars, aes(!!x, !!y, color = !!color)) + 159 | geom_point()+ 160 | scale_color_manual( 161 | values = color_values( 162 | 1:length(unique(pull(big_epa_cars, !!color))), 163 | palette = input$palette 164 | ) 165 | ) 166 | r$code <- sprintf( 167 | "ggplot(big_epa_cars, aes(%s, %s, color = %s)) + 168 | geom_point() + 169 | scale_color_manual( 170 | values = color_values( 171 | 1:length(unique(dplyr::pull(big_epa_cars, %s))), 172 | palette = '%s' 173 | ) 174 | )", 175 | input$x, 176 | input$y, 177 | input$color, 178 | input$color, 179 | input$palette 180 | ) 181 | } 182 | 183 | if (type == "hist"){ 184 | color <- sym(input$color) 185 | r$plot <- ggplot(big_epa_cars, aes(!!x, fill = !!color)) + 186 | geom_histogram(bins = input$bins)+ 187 | scale_fill_manual( 188 | values = color_values( 189 | 1:length(unique(dplyr::pull(big_epa_cars, !!color))), 190 | palette = input$palette 191 | ) 192 | ) 193 | 194 | r$code <- sprintf( 195 | "ggplot(big_epa_cars, aes(%s, fill = %s)) + 196 | geom_histogram(bins = %s)+ 197 | scale_fill_manual( 198 | values = color_values( 199 | 1:length(unique(dplyr::pull(big_epa_cars, %s))), 200 | palette = '%s' 201 | ) 202 | )", 203 | input$x, 204 | input$color, 205 | input$bins, 206 | input$color, 207 | input$palette 208 | ) 209 | } 210 | 211 | if (type == "boxplot"){ 212 | y <- sym(input$y) 213 | r$plot <- ggplot(big_epa_cars, aes(x = !!x, y = !!y)) + 214 | geom_boxplot() 215 | r$code <- sprintf( 216 | "ggplot(big_epa_cars, aes(x = %s, y = %s)) + 217 | geom_boxplot()", 218 | input$x, 219 | input$y 220 | ) 221 | 222 | } 223 | 224 | if (type == "bar"){ 225 | fill <- sym(input$fill) 226 | r$plot <- ggplot(big_epa_cars, aes(!!x, fill = !!fill)) + 227 | geom_bar()+ 228 | scale_fill_manual( 229 | values = color_values( 230 | 1:length(unique(dplyr::pull(big_epa_cars, !!fill))), 231 | palette = input$palette 232 | ) 233 | ) 234 | 235 | r$code <- sprintf( 236 | "ggplot(big_epa_cars, aes(%s, fill = %s)) + 237 | geom_bar()+ 238 | scale_fill_manual( 239 | values = color_values( 240 | 1:length(unique(dplyr::pull(big_epa_cars, %s))), 241 | palette = '%s' 242 | ) 243 | )", 244 | input$x, 245 | input$fill, 246 | input$fill, 247 | input$palette 248 | ) 249 | 250 | if (input$coord_flip){ 251 | r$plot <- r$plot + coord_flip() 252 | 253 | r$code <- sprintf( 254 | "%s 255 | + coord_flip()", 256 | r$code 257 | ) 258 | } 259 | } 260 | 261 | r$plot <- r$plot + 262 | labs(caption = "via https://connect.thinkr.fr/tidytuesday201942") + 263 | get(input$theme)() 264 | 265 | r$code <- sprintf( 266 | '%s + 267 | labs(caption = "via https://connect.thinkr.fr/tidytuesday201942") + 268 | %s()', 269 | r$code, input$theme 270 | ) 271 | 272 | if (input$title != ""){ 273 | r$plot <- r$plot + 274 | labs(title = input$title) 275 | r$code <- sprintf( 276 | '%s +\n labs(title = "%s")', 277 | r$code, input$title 278 | ) 279 | } 280 | }) 281 | 282 | 283 | output$plot <- renderPlot({ 284 | r$plot 285 | }) 286 | 287 | mod <- function() { 288 | modalDialog( 289 | tagList( 290 | tags$code( 291 | id = ns("codeinner"), 292 | tags$pre( 293 | paste(style_text(r$code), collapse = "\n") 294 | ) 295 | ) 296 | ), 297 | footer = tagList( 298 | modalButton("Cancel"), 299 | actionButton(ns("ok"), "OK") 300 | ) 301 | ) 302 | } 303 | 304 | # Show modal when button is clicked. 305 | observeEvent(input$show, { 306 | showModal(mod()) 307 | }) 308 | observeEvent(input$ok, { 309 | removeModal() 310 | }) 311 | 312 | output$code <- renderPlot({ 313 | r$code 314 | }) 315 | 316 | output$dl <- downloadHandler( 317 | filename = function() { 318 | paste('plot-', Sys.Date(), '.png', sep='') 319 | }, 320 | content = function(con) { 321 | ggsave(con,r$plot, device = "png", width = 16, height = 8) 322 | } 323 | ) 324 | } 325 | 326 | 327 | -------------------------------------------------------------------------------- /R/mod_dataviz_utils_ui.R: -------------------------------------------------------------------------------- 1 | names_that_are <- function(class_is){ 2 | r <- sapply(big_epa_cars, class) 3 | names(r[ r %in% class_is]) 4 | } 5 | 6 | #' @importFrom withr with_package 7 | themess <- function(){ 8 | with_package( 9 | "ggplot2", 10 | r <- ls("package:ggplot2", pattern = "^theme_") 11 | ) 12 | r[ 13 | !(r %in% c("theme_get", "theme_replace", "theme_set", "theme_test", "theme_update")) 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /R/mod_raw.R: -------------------------------------------------------------------------------- 1 | # Module UI 2 | 3 | #' @title mod_raw_ui and mod_raw_server 4 | #' @description A shiny Module. 5 | #' 6 | #' @param id shiny id 7 | #' @param input internal 8 | #' @param output internal 9 | #' @param session internal 10 | #' 11 | #' @rdname mod_raw 12 | #' 13 | #' @keywords internal 14 | #' @export 15 | #' @importFrom shiny NS tagList includeMarkdown 16 | mod_raw_ui <- function(id){ 17 | ns <- NS(id) 18 | tagList( 19 | includeMarkdown( 20 | system.file("app/www/home.md", package = "tidytuesday201942") 21 | ) 22 | ) 23 | } 24 | 25 | # Module Server 26 | 27 | #' @rdname mod_raw 28 | #' @export 29 | #' @keywords internal 30 | 31 | mod_raw_server <- function(input, output, session){ 32 | ns <- session$ns 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /R/run_app.R: -------------------------------------------------------------------------------- 1 | #' Run the Shiny Application 2 | #' 3 | #' @param ... list of golem options 4 | #' 5 | #' @export 6 | #' @importFrom shiny shinyApp 7 | #' @importFrom golem with_golem_options 8 | run_app <- function(...) { 9 | with_golem_options( 10 | app = shinyApp(ui = app_ui, server = app_server), 11 | golem_opts = list(...) 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | NULL 12 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # tidytuesday201942 17 | 18 | 19 | [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) 20 | 21 | 22 | The goal of tidytuesday201942 is to visualize data from TIdy Tuesday 2019, October 15th. 23 | 24 | Available at https://connect.thinkr.fr/tidytuesday201942 25 | 26 | Please note that the 'tidytuesday201942' project is released with a 27 | [Contributor Code of Conduct](CODE_OF_CONDUCT.md). 28 | By contributing to this project, you agree to abide by its terms. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # tidytuesday201942 5 | 6 | 7 | 8 | [![Lifecycle: 9 | experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) 10 | 11 | 12 | The goal of tidytuesday201942 is to visualize data from TIdy Tuesday 13 | 2019, October 15th. 14 | 15 | Available at 16 | 17 | Please note that the ‘tidytuesday201942’ project is released with a 18 | [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By contributing to 19 | this project, you agree to abide by its terms. 20 | -------------------------------------------------------------------------------- /app.R: -------------------------------------------------------------------------------- 1 | # Launch the ShinyApp (Do not remove this comment) 2 | # To deploy, run: rsconnect::deployApp() 3 | # Or use the blue button on top of this file 4 | 5 | pkgload::load_all() 6 | options( "golem.app.prod" = TRUE) 7 | tidytuesday201942::run_app() # add parameters here (if any) 8 | -------------------------------------------------------------------------------- /data-raw/big_epa_cars.R: -------------------------------------------------------------------------------- 1 | ## code to prepare `big_epa_cars` dataset goes here 2 | 3 | big_epa_cars <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-10-15/big_epa_cars.csv") 4 | 5 | 6 | usethis::use_data(big_epa_cars) 7 | -------------------------------------------------------------------------------- /data/big_epa_cars.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColinFay/tidytuesday201942/ecefde5f77d90af421fde5e15b4fee26505cfa07/data/big_epa_cars.rda -------------------------------------------------------------------------------- /data/datalist: -------------------------------------------------------------------------------- 1 | big_epa_cars -------------------------------------------------------------------------------- /dev/01_start.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # Each step is optional. 4 | # 5 | # 1 - On init 6 | # 7 | ## 1.1 - Fill the descripion & set options 8 | ## 9 | ## Add information about the package that will contain your app 10 | 11 | golem::fill_desc( 12 | pkg_name = "tidytuesday201942", # The Name of the package containing the App 13 | pkg_title = "A golem App for Tidy Tuesday", # The Title of the package containing the App 14 | pkg_description = "A golem App for Tidy Tuesday.", # The Description of the package containing the App 15 | author_first_name = "Colin", # Your First Name 16 | author_last_name = "Fay", # Your Last Name 17 | author_email = "contact@colinfay.me", # Your Email 18 | repo_url = "http://www.github.com/ColinFay/tidytuesday201942" # The (optional) URL of the GitHub Repo 19 | ) 20 | 21 | ## Use this desc to set {golem} options 22 | 23 | golem::set_golem_options() 24 | 25 | ## 1.2 - Set common Files 26 | ## 27 | ## If you want to use the MIT license, README, code of conduct, lifecycle badge, and news 28 | 29 | usethis::use_mit_license( name = "Colin Fay" ) # You can set another license here 30 | usethis::use_readme_rmd( open = FALSE ) 31 | usethis::use_code_of_conduct() 32 | usethis::use_lifecycle_badge( "Experimental" ) 33 | 34 | usethis::use_news_md( open = FALSE ) 35 | usethis::use_git() 36 | 37 | ## Hide files 38 | usethis::use_build_ignore("CODE_OF_CONDUCT.md") 39 | usethis::use_build_ignore("LICENSE.md") 40 | usethis::use_build_ignore("README.Rmd") 41 | usethis::use_build_ignore("app.R") 42 | usethis::use_build_ignore("data-raw/") 43 | usethis::use_build_ignore("dev/") 44 | usethis::use_build_ignore("manifest.json") 45 | 46 | ## 1.3 - Add a data-raw folder 47 | ## 48 | ## If you have data in your package 49 | usethis::use_data_raw( name = "big_epa_cars", open = FALSE ) # Change "my_dataset" 50 | 51 | ## 1.4 - Init Tests 52 | ## 53 | ## Create a template for tests 54 | 55 | golem::use_recommended_tests() 56 | 57 | ## 1.5 : Use Recommended Package 58 | 59 | golem::use_recommended_deps(recommended = c("shiny", "htmltools")) 60 | 61 | ## 1.6 Add various tools 62 | 63 | # If you want to change the favicon (default is golem's one) 64 | golem::remove_favicon() 65 | golem::use_favicon() # path = "path/to/ico". Can be an online file. 66 | 67 | # Add helper functions 68 | golem::use_utils_ui() 69 | golem::use_utils_server() 70 | 71 | # You're now set! 72 | # go to dev/02_dev.R 73 | rstudioapi::navigateToFile( "dev/02_dev.R" ) 74 | 75 | -------------------------------------------------------------------------------- /dev/02_dev.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # Each step is optional. 4 | # 5 | 6 | # 2. All along your project 7 | 8 | golem::add_fct("nav") 9 | golem::add_fct("row") 10 | 11 | ## 2.1 Add modules 12 | ## 13 | golem::add_module( name = "about" ) # Name of the module 14 | golem::add_module( name = "dataviz" ) # Name of the module 15 | golem::add_module( name = "raw" ) # Name of the module 16 | 17 | golem::add_utils("ui", "dataviz") 18 | ## 2.2 Add dependencies 19 | 20 | usethis::use_package( "glue" ) # To call each time you need a new package 21 | usethis::use_package( "rlang" ) # To call each time you need a new package 22 | usethis::use_package( "dplyr" ) # To call each time you need a new package 23 | usethis::use_package( "styler" ) # To call each time you need a new package 24 | usethis::use_package( "withr" ) # To call each time you need a new package 25 | usethis::use_package( "colourvalues" ) # To call each time you need a new package 26 | usethis::use_package( "markdown" ) # To call each time you need a new package 27 | usethis::use_pipe() 28 | 29 | 30 | attachment::att_amend_desc() 31 | usethis::use_package( "markdown" ) # To call each time you need a new package 32 | 33 | 34 | ## 2.3 Add tests 35 | 36 | usethis::use_test( "app" ) 37 | 38 | ## 2.4 Add a browser button 39 | 40 | golem::browser_button() 41 | 42 | ## 2.5 Add external files 43 | 44 | golem::add_js_file( "script" ) 45 | golem::add_js_handler( "handlers" ) 46 | golem::add_css_file( "custom" ) 47 | 48 | # 3. Documentation 49 | 50 | ## 3.1 Vignette 51 | usethis::use_vignette("tidytuesday201942") 52 | devtools::build_vignettes() 53 | 54 | ## 3.2 Code coverage 55 | ## You'll need GitHub there 56 | usethis::use_github() 57 | usethis::use_travis() 58 | usethis::use_appveyor() 59 | 60 | # You're now set! 61 | # go to dev/03_deploy.R 62 | rstudioapi::navigateToFile("dev/03_deploy.R") 63 | -------------------------------------------------------------------------------- /dev/03_deploy.R: -------------------------------------------------------------------------------- 1 | # Deploy a Prod-Ready, Robust Shiny Application. 2 | # 3 | # 4. Test my package 4 | 5 | devtools::test() 6 | rhub::check_for_cran() 7 | 8 | # 5. Deployment elements 9 | 10 | ## 5.1 If you want to deploy on RStudio related platforms 11 | golem::add_rstudioconnect_file() 12 | golem::add_shinyappsio_file() 13 | golem::add_shinyserver_file() 14 | 15 | ## 5.2 If you want to deploy via a generic Dockerfile 16 | golem::add_dockerfile() 17 | 18 | ## 5.2 If you want to deploy to ShinyProxy 19 | golem::add_dockerfile_shinyproxy() 20 | 21 | ## 5.2 If you want to deploy to Heroku 22 | golem::add_dockerfile_heroku() 23 | -------------------------------------------------------------------------------- /dev/run_dev.R: -------------------------------------------------------------------------------- 1 | # Set options here 2 | options(golem.app.prod = FALSE) # TRUE = production mode, FALSE = development mode 3 | 4 | # Detach all loaded packages and clean your environment 5 | golem::detach_all_attached() 6 | # rm(list=ls(all.names = TRUE)) 7 | 8 | # Document and reload your package 9 | golem::document_and_reload() 10 | 11 | # Run the application 12 | tidytuesday201942::run_app() 13 | -------------------------------------------------------------------------------- /inst/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColinFay/tidytuesday201942/ecefde5f77d90af421fde5e15b4fee26505cfa07/inst/.DS_Store -------------------------------------------------------------------------------- /inst/app/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColinFay/tidytuesday201942/ecefde5f77d90af421fde5e15b4fee26505cfa07/inst/app/.DS_Store -------------------------------------------------------------------------------- /inst/app/www/about.md: -------------------------------------------------------------------------------- 1 | ## About this app 2 | 3 | This app has been built by [Colin Fay](https://twitter.com/_ColinFay), as an illustration of an app built using the `{golem}` Framework. It's based on a dataset from [Tidy Tuesday 2019-10-15](https://github.com/rfordatascience/tidytuesday/tree/master/data/2019/2019-10-15). 4 | 5 | Colin works at [ThinkR](https://rtask.thinkr.fr), a french company focused on R engineering, creator and maintainer of the `{golem}` package. 6 | 7 | ### Find ThinkR on : 8 | 9 | + [The web](https://rtask.thinkr.fr) 10 | + [Twitter](https://twitter.com/ThinkR_FR) 11 | + [GitHub](https://github.com/ThinkR-open) 12 | -------------------------------------------------------------------------------- /inst/app/www/custom.css: -------------------------------------------------------------------------------- 1 | /* background color of the navbar */ 2 | .navbar{ background: white;} 3 | 4 | /*Change the color of the link + put hand on hover */ 5 | .nav-link , .navbar-brand{ color: #000000; cursor: pointer;} 6 | 7 | /* Margin of the links in the nav */ 8 | .nav-link{ margin-right: 1em !important;} 9 | 10 | /* background color on hover of the nav links */ 11 | .nav-link:hover{ background: #f4f4f4; color: #f97300; } 12 | 13 | /* background color of the navbar */ 14 | .navbar-collapse{ justify-content: flex-end;} 15 | 16 | /* background color of the navbar */ 17 | .navbar-toggler{ background:#fff !important;} 18 | 19 | .navbar { 20 | /*border-top: 2px solid black; */ 21 | border-bottom: 2px solid black; 22 | padding-top : 2em; 23 | padding-left : 5em; 24 | padding-right : 5em; 25 | } 26 | 27 | .row{ 28 | margin-top:2em; 29 | } 30 | 31 | .container { 32 | margin-right: 6em; 33 | margin-left: 6em; 34 | } 35 | 36 | .btn { 37 | border: 1px solid #ced4da; 38 | } 39 | 40 | blockquote { 41 | font-size: 0.75em; 42 | } -------------------------------------------------------------------------------- /inst/app/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ColinFay/tidytuesday201942/ecefde5f77d90af421fde5e15b4fee26505cfa07/inst/app/www/favicon.ico -------------------------------------------------------------------------------- /inst/app/www/home.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 8 | 9 |

Exploring the "Big mtcars" dataset

10 | 11 |

This application allows you to build your own dataviz for #TidyTuesday, 2019-10-15. 12 | 13 |

Tidy Tuesday is a weekly social data project in R. Find more about this project on rfordatasci.com and on the GitHub repo. 14 | 15 |

This week dataset is a larger version of the well-known mtcars dataset. With this application, you'll be able to build your own {ggplot2} graph out of this dataset.

16 | 17 |

On each plot, once it's rendered, you'll be able to see the code used by clicking on the image. You can use it as a starting point for more customisation.

18 | 19 |

For a deeper understanding of the dataset, feel free to unfold the data dictionnary on the bottom of this page.

20 | 21 | 22 |

You can also jump to:

23 | 24 | 32 | 33 | 47 | 48 | 49 |
50 | Click to display variable dictionnary. 51 | 52 |
  • atvtype - type of alternative fuel or advanced technology vehicle
  • 53 |
  • barrels08 - annual petroleum consumption in barrels for fuelType1 (1)
  • 54 |
  • barrelsA08 - annual petroleum consumption in barrels for fuelType2 (1)
  • 55 |
  • charge120 - time to charge an electric vehicle in hours at 120 V
  • 56 |
  • charge240 - time to charge an electric vehicle in hours at 240 V
  • 57 |
  • city08 - city MPG for fuelType1 (2), (11)
  • 58 |
  • city08U - unrounded city MPG for fuelType1 (2), (3)
  • 59 |
  • cityA08 - city MPG for fuelType2 (2)
  • 60 |
  • cityA08U - unrounded city MPG for fuelType2 (2), (3)
  • 61 |
  • cityCD - city gasoline consumption (gallons/100 miles) in charge depleting mode (4)
  • 62 |
  • cityE - city electricity consumption in kw-hrs/100 miles
  • 63 |
  • cityUF - EPA city utility factor (share of electricity) for PHEV
  • 64 |
  • co2 - tailpipe CO2 in grams/mile for fuelType1 (5)
  • 65 |
  • co2A - tailpipe CO2 in grams/mile for fuelType2 (5)
  • 66 |
  • co2TailpipeAGpm - tailpipe CO2 in grams/mile for fuelType2 (5)
  • 67 |
  • co2TailpipeGpm- tailpipe CO2 in grams/mile for fuelType1 (5)
  • 68 |
  • comb08 - combined MPG for fuelType1 (2), (11)
  • 69 |
  • comb08U - unrounded combined MPG for fuelType1 (2), (3)
  • 70 |
  • combA08 - combined MPG for fuelType2 (2)
  • 71 |
  • combA08U - unrounded combined MPG for fuelType2 (2), (3)
  • 72 |
  • combE - combined electricity consumption in kw-hrs/100 miles
  • 73 |
  • combinedCD - combined gasoline consumption (gallons/100 miles) in charge depleting mode (4)
  • 74 |
  • combinedUF - EPA combined utility factor (share of electricity) for PHEV
  • 75 |
  • cylinders - engine cylinders
  • 76 |
  • displ - engine displacement in liters
  • 77 |
  • drive - drive axle type
  • 78 |
  • emissionsList
  • 79 |
  • engId - EPA model type index
  • 80 |
  • eng_dscr - engine descriptor; see http://www.fueleconomy.gov/feg/findacarhelp.shtml#engine
  • 81 |
  • evMotor - electric motor (kw-hrs)
  • 82 |
  • feScore - EPA Fuel Economy Score (-1 = Not available)
  • 83 |
  • fuelCost08 - annual fuel cost for fuelType1 ($) (7)
  • 84 |
  • fuelCostA08 - annual fuel cost for fuelType2 ($) (7)
  • 85 |
  • fuelType - fuel type with fuelType1 and fuelType2 (if applicable)
  • 86 |
  • fuelType1 - fuel type 1. For single fuel vehicles, this will be the only fuel. For dual fuel vehicles, this will be + the conventional fuel.
  • 87 |
  • fuelType2 - fuel type 2. For dual fuel vehicles, this will be the alternative fuel (e.g. E85, Electricity, CNG, + LPG). For single fuel vehicles, this field is not used
  • 88 |
  • ghgScore - EPA GHG score (-1 = Not available)
  • 89 |
  • ghgScoreA - EPA GHG score for dual fuel vehicle running on the alternative fuel (-1 = Not available)
  • 90 |
  • guzzler- if G or T, this vehicle is subject to the gas guzzler tax
  • 91 |
  • highway08 - highway MPG for fuelType1 (2), (11)
  • 92 |
  • highway08U - unrounded highway MPG for fuelType1 (2), (3)
  • 93 |
  • highwayA08 - highway MPG for fuelType2 (2)
  • 94 |
  • highwayA08U - unrounded highway MPG for fuelType2 (2),(3)
  • 95 |
  • highwayCD - highway gasoline consumption (gallons/100miles) in charge depleting mode (4)
  • 96 |
  • highwayE - highway electricity consumption in kw-hrs/100 miles
  • 97 |
  • highwayUF - EPA highway utility factor (share of electricity) for PHEV
  • 98 |
  • hlv - hatchback luggage volume (cubic feet) (8)
  • 99 |
  • hpv - hatchback passenger volume (cubic feet) (8)
  • 100 |
  • id - vehicle record id
  • 101 |
  • lv2 - 2 door luggage volume (cubic feet) (8)
  • 102 |
  • lv4 - 4 door luggage volume (cubic feet) (8)
  • 103 |
  • make - manufacturer (division)
  • 104 |
  • mfrCode - 3-character manufacturer code
  • 105 |
  • model - model name (carline)
  • 106 |
  • mpgData - has My MPG data; see yourMpgVehicle and yourMpgDriverVehicle
  • 107 |
  • phevBlended - if true, this vehicle operates on a blend of gasoline and electricity in charge depleting mode
  • 108 |
  • pv2 - 2-door passenger volume (cubic feet) (8)
  • 109 |
  • pv4 - 4-door passenger volume (cubic feet) (8)
  • 110 |
  • rangeA - EPA range for fuelType2
  • 111 |
  • rangeCityA - EPA city range for fuelType2
  • 112 |
  • rangeHwyA - EPA highway range for fuelType2
  • 113 |
  • trans_dscr - transmission descriptor; see http://www.fueleconomy.gov/feg/findacarhelp.shtml#trany
  • 114 |
  • trany - transmission
  • 115 |
  • UCity - unadjusted city MPG for fuelType1; see the description of the EPA test procedures
  • 116 |
  • UCityA - unadjusted city MPG for fuelType2; see the description of the EPA test procedures
  • 117 |
  • UHighway - unadjusted highway MPG for fuelType1; see the description of the EPA test procedures
  • 118 |
  • UHighwayA - unadjusted highway MPG for fuelType2; see the description of the EPA test procedures
  • 119 |
  • VClass - EPA vehicle size class
  • 120 |
  • year - model year
  • 121 |
  • youSaveSpend - you save/spend over 5 years compared to an average car ($). Savings are positive; a greater amount + spent yields a negative number. For dual fuel vehicles, this is the cost savings for gasoline
  • 122 |
  • sCharger - if S, this vehicle is supercharged
  • 123 |
  • tCharger - if T, this vehicle is turbocharged
  • 124 |
  • c240Dscr - electric vehicle charger description
  • 125 |
  • charge240b - time to charge an electric vehicle in hours at 240 V using the alternate charger
  • 126 |
  • c240bDscr - electric vehicle alternate charger description
  • 127 |
  • createdOn - date the vehicle record was created (ISO 8601 format)
  • 128 |
  • modifiedOn - date the vehicle record was last modified (ISO 8601 format)
  • 129 |
  • startStop - vehicle has start-stop technology (Y, N, or blank for older vehicles)
  • 130 |
  • phevCity - EPA composite gasoline-electricity city MPGe for plug-in hybrid vehicles
  • 131 |
  • phevHwy - EPA composite gasoline-electricity highway MPGe for plug-in hybrid vehicles
  • 132 |
  • phevComb - EPA composite gasoline-electricity combined city-highway MPGe for plug-in hybrid vehicles
  • 133 | 134 |
    135 | 136 |
    137 | -------------------------------------------------------------------------------- /inst/app/www/script.js: -------------------------------------------------------------------------------- 1 | $(function(){ 2 | $( ".row" ).hide(); 3 | $( ".row" ).first().show(); 4 | $( ".nav-link" ).first().addClass("active"); 5 | var h = parseInt($('nav').outerHeight()) + 30; 6 | $(".row").css("padding-top", h + "px"); 7 | 8 | 9 | }) -------------------------------------------------------------------------------- /inst/app/www/tech.md: -------------------------------------------------------------------------------- 1 | ## Tech used in this app 2 | 3 | + The [`{golem}`](https://github.com/ThinkR-open/golem) Framework was used to build the Shiny App backend. 4 | 5 | + The whole app is powererd by [`{shiny}`](https://github.com/rstudio/shiny). 6 | 7 | + Datavisualisation is done with [`{ggplot2}`](https://github.com/tidyverse/ggplot2) 8 | 9 | + The UI was built with [`Boostrap`](https://getbootstrap.com/) 10 | 11 | + The app was deployed on [RStudio Connect](https://rstudio.com/products/connect/) 12 | 13 | Browse the full source code at https://github.com/ColinFay/tidytuesday201942 14 | -------------------------------------------------------------------------------- /inst/golem-config.yml: -------------------------------------------------------------------------------- 1 | default: 2 | golem_name: shinyexample 3 | golem_version: 0.0.0.9000 4 | app_prod: no 5 | 6 | production: 7 | app_prod: yes 8 | 9 | dev: 10 | golem_wd: !expr golem::pkg_path() 11 | 12 | -------------------------------------------------------------------------------- /man/big_epa_cars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/datasets.R 3 | \docType{data} 4 | \name{big_epa_cars} 5 | \alias{big_epa_cars} 6 | \title{big_epa_cars} 7 | \format{ 8 | Tibble with 41,804 features and 83 fields 9 | } 10 | \usage{ 11 | big_epa_cars 12 | } 13 | \description{ 14 | Dataset from tidytuesday: rfordatascience/tidytuesday 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/mod_about.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mod_about.R 3 | \name{mod_about_ui} 4 | \alias{mod_about_ui} 5 | \alias{mod_about_server} 6 | \title{mod_about_ui and mod_about_server} 7 | \usage{ 8 | mod_about_ui(id) 9 | 10 | mod_about_server(input, output, session) 11 | } 12 | \arguments{ 13 | \item{id}{shiny id} 14 | 15 | \item{input}{internal} 16 | 17 | \item{output}{internal} 18 | 19 | \item{session}{internal} 20 | } 21 | \description{ 22 | A shiny Module. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/mod_dataviz.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mod_dataviz.R 3 | \name{mod_dataviz_ui} 4 | \alias{mod_dataviz_ui} 5 | \alias{mod_dataviz_server} 6 | \title{mod_dataviz_ui and mod_dataviz_server} 7 | \usage{ 8 | mod_dataviz_ui(id, type = c("point", "hist", "boxplot", "bar")) 9 | 10 | mod_dataviz_server(input, output, session, type) 11 | } 12 | \arguments{ 13 | \item{id}{shiny id} 14 | 15 | \item{input}{internal} 16 | 17 | \item{output}{internal} 18 | 19 | \item{session}{internal} 20 | } 21 | \description{ 22 | A shiny Module. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/mod_raw.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mod_raw.R 3 | \name{mod_raw_ui} 4 | \alias{mod_raw_ui} 5 | \alias{mod_raw_server} 6 | \title{mod_raw_ui and mod_raw_server} 7 | \usage{ 8 | mod_raw_ui(id) 9 | 10 | mod_raw_server(input, output, session) 11 | } 12 | \arguments{ 13 | \item{id}{shiny id} 14 | 15 | \item{input}{internal} 16 | 17 | \item{output}{internal} 18 | 19 | \item{session}{internal} 20 | } 21 | \description{ 22 | A shiny Module. 23 | } 24 | \keyword{internal} 25 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \description{ 10 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/run_app.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_app.R 3 | \name{run_app} 4 | \alias{run_app} 5 | \title{Run the Shiny Application} 6 | \usage{ 7 | run_app(...) 8 | } 9 | \arguments{ 10 | \item{...}{list of golem options} 11 | } 12 | \description{ 13 | Run the Shiny Application 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(tidytuesday201942) 3 | 4 | test_check("tidytuesday201942") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-golem-recommended.R: -------------------------------------------------------------------------------- 1 | context("golem tests") 2 | 3 | library(golem) 4 | 5 | test_that("app ui", { 6 | ui <- app_ui() 7 | expect_shinytaglist(ui) 8 | }) 9 | 10 | test_that("app server", { 11 | server <- app_server 12 | expect_is(server, "function") 13 | }) 14 | 15 | # Configure this test to fit your need 16 | test_that( 17 | "app launches",{ 18 | skip_on_cran() 19 | skip_on_travis() 20 | skip_on_appveyor() 21 | x <- processx::process$new( 22 | "R", 23 | c( 24 | "-e", 25 | "setwd('../../'); pkgload::load_all();run_app()" 26 | ) 27 | ) 28 | Sys.sleep(5) 29 | expect_true(x$is_alive()) 30 | x$kill() 31 | } 32 | ) 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /tidytuesday201942.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageUseDevtools: Yes 17 | PackageInstallArgs: --no-multiarch --with-keep.source 18 | --------------------------------------------------------------------------------