Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. ---
  2. title: "A15 Dashboard"
  3. output: html_notebook
  4. ---
  5.  
  6. By Noah Perry and Andrew Hall
  7.  
  8. 1. Build a dashboard to report the total amount and number of checks received for ClassicModels for a given year and month.
  9. 2. Submit a pdf of the code and dashboard April 2005.
  10.  
  11. ```{r}
  12. library(tidyverse)
  13. library(lubridate)
  14. library(shiny)
  15. library(shinydashboard)
  16.  
  17. #Creating Header, Sidebar, and Sidebar menu
  18. header <- dashboardHeader(title="ClassicModels Monthly Revenue and Order Volume")
  19. monthOption<-menuItem(selectInput(inputId = "month", "Pick a Month", c(1:12), NULL, FALSE, FALSE))
  20. yearOption<-menuItem(selectInput(inputId = "year", "Pick a Year", c(2003:2005), NULL, FALSE, FALSE))
  21. sideMenu<-sidebarMenu(monthOption,yearOption)
  22. sidebar <- dashboardSidebar(sideMenu)
  23.  
  24. #Formatting Body and UI
  25. body <- dashboardBody(tableOutput("tbl"))
  26. ui <- dashboardPage(header, sidebar, body)
  27.  
  28. server <- function(input, output,session) {
  29. #Rendered Table based on user menu input
  30. output$tbl <- renderTable({
  31. #DB connection
  32. conn<-dbConnect(RMySQL::MySQL(),"richardtwatson.com",dbname="ClassicModels",user="student",password="student")
  33. on.exit(dbDisconnect(conn), add = TRUE)
  34. #Dynamic SQL query
  35. sql<-"Select sum(amount) as 'Monthly Revenue', count(checkNumber) as 'Number of Orders' from Payments where Month(paymentDate) = ?month AND Year(paymentDate)=?year;"
  36. query<-sqlInterpolate(conn, sql, year = input$year, month = input$month)
  37. dbGetQuery(conn, query)
  38. })
  39. }
  40. shinyApp(ui, server)
  41.  
  42. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement