Guest User

Untitled

a guest
Sep 13th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #packages needed
  2. library(plotly)
  3. library(shiny)
  4. library(DBI)
  5. library(RMySQL)
  6. #connecting db
  7. dealerinventory1<-dbConnect(RMySQL::MySQL(), user='kapow_root',
  8. password='dfgfdgdg!',
  9. host='hfghfh',
  10. dbname='hhthhq23u')
  11.  
  12.  
  13. uscount1=dbGetQuery(dealerinventory1,
  14. 'SELECT count(distinct makename) as USmakes FROM dealer_inventory.CarQuery;')
  15.  
  16. autongincount1=dbGetQuery(dealerinventory1,
  17. 'SELECT count(distinct makename) as autonginmakes FROM dealer_inventory.car_inventory_json_lookup;')
  18.  
  19.  
  20. usandautongintable <- c(autongincount1,uscount1)
  21. usandautongintable
  22. label <- c(paste("Autongin Count: ", autongincount1),paste("US Industry Count: ", uscount1))
  23. label
  24.  
  25. unlist <- as.numeric(unlist(usandautongintable))
  26.  
  27. typeof(unlist)
  28. #table used for plotting
  29. table<- as.data.frame(usandautongintable)
  30. table
  31. #for plotting pie chart
  32. plotpie<- plot_ly(table, labels = label,values = unlist, type = "pie") %>%
  33. layout(title = 'Comparison of Makes',
  34. xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
  35. yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
  36.  
  37. plotpie
  38.  
  39. library(shiny)
  40. library(plotly)
  41.  
  42.  
  43. ui= fluidPage(
  44. plotlyOutput("plot")
  45. )
  46.  
  47.  
  48. server1<- function(input,output){
  49. output$plot=renderPlotly({
  50. plot_ly(table, labels = label,values = unlist, type = "pie") %>%
  51. layout(title = 'Comparison of Makes',
  52. xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
  53. yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
  54. })
  55. }
  56.  
  57. shinyApp(ui,server1)
Add Comment
Please, Sign In to add comment