Car Selector is based on the now very famous mtcars database, which was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
27 avril 2018
Car Selector is based on the now very famous mtcars database, which was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
The user is asked to fill in its selection criteria
sidebarPanel( sliderInput("mpg", "What is the the gaz consumpion you want, as a minimum miles per galon?", min = floor(min(mtcars$mpg)), max = ceiling(max(mtcars$mpg)), value = median(mtcars$mpg)), sliderInput("hp", "What is the power range you want, in horsepower?", min = floor(min(mtcars$hp)), max = ceiling(max(mtcars$hp)), value = c(median(mtcars$hp)*0.75,median(mtcars$hp)*1.25)), numericInput("wt", "What is the maximum wheight you want, in lbs?", value = 1.5*1000*median(mtcars$wt)), selectInput("am", "What kind of transmission do you what?", c("Automatic","Manual"))
The server process the data base and return the correct selection of observation based on the selection criteria inputed by the user. The complete code behind server.R
shinyServer(function(input, output) { ## Processing dataframe mtcars2 <- data.frame(Name = rownames(mtcars), MilesPerGallon = mtcars$mpg, Weight = mtcars$wt, HorsePower = mtcars$hp, Transmission = mtcars$am) mtcars2$Weight <- mtcars2$Weight*1000 mtcars2$Transmission <- ifelse(mtcars2$Transmission == 0, "Automatic", "Manual") ## Selecting upon filters selection <- reactive( mtcars2 %>% select(Name, Weight, HorsePower, Transmission, MilesPerGallon) %>% filter(MilesPerGallon > input$mpg) %>% filter(HorsePower > input$hp[1]) %>% filter(HorsePower < input$hp[2]) %>% filter(Weight < input$wt) %>% filter(Transmission == input$am) ) output$Table <- renderTable({ selection() }) })
fluidRow( column(12, tableOutput("Table") ) ),