Skip to content

Commit

Permalink
Beginning to build modules
Browse files Browse the repository at this point in the history
  • Loading branch information
skanderkam committed Dec 13, 2018
1 parent 7519a2d commit 53cf192
Show file tree
Hide file tree
Showing 48 changed files with 252,084 additions and 2 deletions.
7 changes: 7 additions & 0 deletions package/findyourdreamcar/.Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
^devstuff_history\.R$
^.*\.Rproj$
^\.Rproj\.user$
^data-raw$
^devtools_history\.R$
devtstuff_history.R
^devtstuff_history\.R$
1 change: 1 addition & 0 deletions package/findyourdreamcar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.Rproj.user
30 changes: 30 additions & 0 deletions package/findyourdreamcar/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Package: findyourdreamcar
Title: A shiny template
Version: 0.1.2
Authors@R: person("Vincent", "Guyader", email = "vincent@thinkr.fr", role = c("aut", "cre"))
Description: A template for prod-ready Shiny App.
License: GPL-3
Depends:
R (>= 3.4.3)
Imports:
DT,
glue,
graphics,
shiny,
stats,
dplyr,
magrittr,
RColorBrewer,
readr,
sf,
ggplot2,
raster,
rasterVis
Suggests:
testthat,
knitr,
rmarkdown
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
VignetteBuilder: knitr
19 changes: 19 additions & 0 deletions package/findyourdreamcar/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by roxygen2: do not edit by hand

export(mod_advanced_filtering)
export(mod_advanced_filteringUI)
export(mod_basic_filtering)
export(mod_basic_filteringUI)
export(mod_csv_file)
export(mod_csv_fileInput)
export(run_app)
import(dplyr)
import(magrittr)
import(shiny)
importFrom(glue,glue)
importFrom(graphics,hist)
importFrom(shiny,addResourcePath)
importFrom(shiny,shinyApp)
importFrom(stats,rnorm)
importFrom(utils,data)
importFrom(utils,read.csv)
10 changes: 10 additions & 0 deletions package/findyourdreamcar/R/app_prod.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
`%||%` <- function (x, y)
{
if (is.null(x))
y
else x
}
#' return `TRUE` if in `production mode`
app_prod <- function(){
getOption( "app.prod" ) %||% TRUE
}
15 changes: 15 additions & 0 deletions package/findyourdreamcar/R/app_server.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' @import shiny
#' @importFrom graphics hist
#' @importFrom stats rnorm
#'
app_server <- function(input, output,session) {

if ( app_prod() ){message("prod mode")}else{message("dev mode")}
output$distPlot <- renderPlot({
x <- rnorm(1000)
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})


}
23 changes: 23 additions & 0 deletions package/findyourdreamcar/R/app_ui.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#' @import shiny
app_ui <- function() {
fluidPage(
titlePanel("Find Your Dream Car"),
sidebarLayout(
sidebarPanel(
mod_basic_filteringUI("fichier")
),
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Complementary Adjustments",
# Left column with adjustment inputs
column(6,
mod_advanced_filteringUI("fichier")
)),
tabPanel("At 30 min drive", h5("")),
tabPanel("In the whole country", h5(""))
)
)
)
)
}
52 changes: 52 additions & 0 deletions package/findyourdreamcar/R/mod_advanced_filteringUI.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#' @title mod_advanced_fileringUI and mod_advanced_filtering
#' @description A shiny Module that allows the user to select the advanced filters
#'
#' @import dplyr
#' @import magrittr
#' @export
#' @examples
#' library(shiny)
#' library(DT)
#' if (interactive()){
#' ui <- fluidPage(
#' mod_csv_fileInput("fichier"),
#' DTOutput("tableau")
#' )
#'
#' server <- function(input, output, session) {
#' data <- callModule(mod_csv_file,"fichier")
#' output$tableau <- renderDT({data()})
#' }
#'
#' shinyApp(ui, server)
#' }
#'
mod_advanced_filteringUI <- function(id) {

ns <- NS(id)

tagList(
selectInput(ns("transmission"), "Choose the type of transmission:", choices = c("No Preference", cardata$transmission[!is.na(cardata$transmission)] %>% unique())),
selectInput(ns("brand"), "Brand:", choices = c("No Preference", cardata$brand[!is.na(cardata$brand)] %>% unique() %>% sort())),
sliderInput(ns("year_built"), "Year:", min = 1950, max = 2017, value = c(1950,2017)),
sliderInput(ns("mileage"), "Mileage:", min = 10000, max = 100000, value = c(10000, 100000)),
selectInput(ns("fuel"), "Type of fuel:", choices = c("No Preference", cardata$energie[!is.na(cardata$energie)] %>% unique() %>% sort())),
selectInput(ns("nb_seats"), "Number of seats:", choices = c("No Preference", cardata$nb_places[!is.na(cardata$nb_places)] %>% unique() %>% sort())),
selectInput(ns("nb_doors"), "Number of doors:", choices = c("No Preference", cardata$nb_portes[!is.na(cardata$nb_portes)] %>% unique() %>% sort()))
)

}


#' mod_basic_filtering server function
#'
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @importFrom utils data
#' @export
#' @rdname mod_advanced_filteringUI
mod_advanced_filtering <- function(input, output, session) {

}
73 changes: 73 additions & 0 deletions package/findyourdreamcar/R/mod_basic_filteringUI.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Naming convention :
# all Shinymodule have to begin with `mod_`, in lowercase Except for `UI` , `Input` and `Output`
# use `Input` as sufix if your module is an Input
# use `Output` as sufix if your module is an Output
# use `UI` as sufix if your module is both Input and Output
#
# examples :
# ui side : mod_truc_bidulUI
# server side : mod_truc_bidul
#
# ui side : mod_machin_chouetteInput
# server side : mod_machin_chouette

# all shinyModule must have a documentation page
# one unique page for both ui and server side ( you can use `#' @rdname` to link both function)

# A minimalist example is mandatory

#' @title mod_basic_fileringUI and mod_basic_filtering
#' @description A shiny Module that allows the user to select basic filters
#'
#' @import dplyr
#' @import magrittr
#' @export
#' @examples
#' library(shiny)
#' library(DT)
#' if (interactive()){
#' ui <- fluidPage(
#' mod_csv_fileInput("fichier"),
#' DTOutput("tableau")
#' )
#'
#' server <- function(input, output, session) {
#' data <- callModule(mod_csv_file,"fichier")
#' output$tableau <- renderDT({data()})
#' }
#'
#' shinyApp(ui, server)
#' }
#'
mod_basic_filteringUI <- function(id) {

ns <- NS(id)

tagList(
# Select Input for the Postal Code:
selectInput(ns("city"), "Select your city:", choices = cardata$nom_commune %>% unique %>% sort()),

# Select type of car: for the time being, choices are linked to factors taken by Carosserie in the first raw dataset
selectInput(ns("carrosserie"), "Choose the type of car:", choices = cardata$carrosserie %>% unique()),

# Action Button (to be automatized)
actionButton(ns("go"), "Go")
)

}


#' mod_basic_filtering server function
#'
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @importFrom utils data
#' @export
#' @rdname mod_basic_filteringUI
mod_basic_filtering <- function(input, output, session) {

#data("cardata")

}
73 changes: 73 additions & 0 deletions package/findyourdreamcar/R/mod_country_statsUI.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Naming convention :
# all Shinymodule have to begin with `mod_`, in lowercase Except for `UI` , `Input` and `Output`
# use `Input` as sufix if your module is an Input
# use `Output` as sufix if your module is an Output
# use `UI` as sufix if your module is both Input and Output
#
# examples :
# ui side : mod_truc_bidulUI
# server side : mod_truc_bidul
#
# ui side : mod_machin_chouetteInput
# server side : mod_machin_chouette

# all shinyModule must have a documentation page
# one unique page for both ui and server side ( you can use `#' @rdname` to link both function)

# A minimalist example is mandatory

#' @title mod_basic_fileringUI and mod_basic_filtering
#' @description A shiny Module that allows the user to select basic filters
#'
#' @import dplyr
#' @import magrittr
#' @export
#' @examples
#' library(shiny)
#' library(DT)
#' if (interactive()){
#' ui <- fluidPage(
#' mod_csv_fileInput("fichier"),
#' DTOutput("tableau")
#' )
#'
#' server <- function(input, output, session) {
#' data <- callModule(mod_csv_file,"fichier")
#' output$tableau <- renderDT({data()})
#' }
#'
#' shinyApp(ui, server)
#' }
#'
mod_basic_filteringUI <- function(id) {

ns <- NS(id)

tagList(
# Select Input for the Postal Code:
selectInput(ns("city"), "Select your city:", choices = cardata$nom_commune %>% unique %>% sort()),

# Select type of car: for the time being, choices are linked to factors taken by Carosserie in the first raw dataset
selectInput(ns("carrosserie"), "Choose the type of car:", choices = cardata$carrosserie %>% unique()),

# Action Button (to be automatized)
actionButton(ns("go"), "Go")
)

}


#' mod_basic_filtering server function
#'
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @importFrom utils data
#' @export
#' @rdname mod_basic_filteringUI
mod_basic_filtering <- function(input, output, session) {

#data("cardata")

}
Loading

0 comments on commit 53cf192

Please sign in to comment.