diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/R-Test-Project.Rproj b/R-Test-Project.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/R-Test-Project.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/server.R b/server.R new file mode 100644 index 0000000..6c108c4 --- /dev/null +++ b/server.R @@ -0,0 +1,42 @@ +# +# This is the server logic of a Shiny web application. You can run the +# application by clicking 'Run App' above. +# +# Find out more about building applications with Shiny here: +# +# http://shiny.rstudio.com/ +# + + +library(shiny) +library(leaflet) +library(data.table) +library(lubridate) +library(DT) + +# Define server logic required to draw a histogram +shinyServer(function(input, output) { + + d <- fread("/Volumes/Nifty/Cloudstation/_Uni/Master/actual/FS2018/R-NonTechnicalIntroduction/02_Exercises/data/demographics.csv") + d[, JoinDate:=dmy(JoinDate, tz="UTC")] + #zips <- as.matrix(d[1:10000, list(zip_longitude, zip_latitude, Gender)]) + + d.shiny <- reactive({ + d[Gender %in% input$genderWidget & JoinDate >= input$date[1] & JoinDate <= input$date[2]] + }) + + # Define map and fill map with data points + output$mymap <- renderLeaflet({ + map <- leaflet(); + map <- addTiles(map); + map <- addMarkers(map, lng = d.shiny()[,zip_longitude], + lat =d.shiny()[,zip_latitude], + clusterOptions = markerClusterOptions()); + map <- setView(map, lat= 43, lng= -79, zoom = 4); # North America + }) + + # Table Output for Tab + output$mydata <- DT::renderDataTable(d.shiny()) + + +}) diff --git a/ui.R b/ui.R new file mode 100644 index 0000000..e7607ce --- /dev/null +++ b/ui.R @@ -0,0 +1,46 @@ +# +# This is the user-interface definition of a Shiny web application. You can +# run the application by clicking 'Run App' above. +# +# Find out more about building applications with Shiny here: +# +# http://shiny.rstudio.com/ +# + + +library(shiny) +library(leaflet) +library(data.table) +library(shinythemes) +library(lubridate) + + +# Define UI for application that draws a histogram +shinyUI(fluidPage( + + theme = shinytheme("simplex"), + # Application title + titlePanel("Customer map"), + + sidebarLayout(position = "left", + sidebarPanel("Inputs", + checkboxGroupInput("genderWidget", + label ="Gender Choice", + choices = list("Male" = "m", + "Female" = "f", + "Alien" = "alien"), + selected = c("f","m", "alien") + ), + sliderInput("date", + label = "Dates:", + min = dmy("01.01.1965"), + max = dmy("31.12.2011"), + value=c(dmy("01.01.1965"), dmy("31.12.2011")) + )), + mainPanel( + tabsetPanel( + tabPanel("Map", leafletOutput("mymap", height = "800px")), + tabPanel("Data", DT::dataTableOutput('mydata')) + ) + )) +)) \ No newline at end of file