Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #packages needed
- library(plotly)
- library(shiny)
- library(DBI)
- library(RMySQL)
- #connecting db
- dealerinventory1<-dbConnect(RMySQL::MySQL(), user='kapow_root',
- password='dfgfdgdg!',
- host='hfghfh',
- dbname='hhthhq23u')
- uscount1=dbGetQuery(dealerinventory1,
- 'SELECT count(distinct makename) as USmakes FROM dealer_inventory.CarQuery;')
- autongincount1=dbGetQuery(dealerinventory1,
- 'SELECT count(distinct makename) as autonginmakes FROM dealer_inventory.car_inventory_json_lookup;')
- usandautongintable <- c(autongincount1,uscount1)
- usandautongintable
- label <- c(paste("Autongin Count: ", autongincount1),paste("US Industry Count: ", uscount1))
- label
- unlist <- as.numeric(unlist(usandautongintable))
- typeof(unlist)
- #table used for plotting
- table<- as.data.frame(usandautongintable)
- table
- #for plotting pie chart
- plotpie<- plot_ly(table, labels = label,values = unlist, type = "pie") %>%
- layout(title = 'Comparison of Makes',
- xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
- yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
- plotpie
- library(shiny)
- library(plotly)
- ui= fluidPage(
- plotlyOutput("plot")
- )
- server1<- function(input,output){
- output$plot=renderPlotly({
- plot_ly(table, labels = label,values = unlist, type = "pie") %>%
- layout(title = 'Comparison of Makes',
- xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
- yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
- })
- }
- shinyApp(ui,server1)
Add Comment
Please, Sign In to add comment