Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. library(RJDBC)
  2. library(dplyr)
  3. library(shiny)
  4. library(ggplot2)
  5. library(scales)
  6. library(shinydashboard)
  7. library(gridExtra)
  8. library(DT)
  9. library(ggthemes)
  10. library(plotly)
  11. library(reshape2)
  12. library(shinyWidgets)
  13. dsn_driver = ""
  14. dsn_database = "" # e.g. "BLUDB"
  15. dsn_hostname = "" # e.g.: "awh-yp-small03.services.dal.bluemix.net"
  16. dsn_port = "" # e.g. "50000"
  17. dsn_protocol = "" # i.e. "TCPIP"
  18. dsn_uid = "" # e.g. "dash104434"
  19. dsn_pwd = ""
  20. jcc = JDBC("", "");
  21. jdbc_path = paste("jdbc:db2://", dsn_hostname, ":", dsn_port, "/", dsn_database, sep="");
  22. conn = dbConnect(jcc, jdbc_path, user=dsn_uid, password=dsn_pwd)
  23. query ="select RETAIL_STR_AREA_WISE.STORE_NM as ST,RETAIL_STORE_AREA_WISE.TOWN_NAME as TOWN_NAME,RETAIL_STORE_AREA_WISE.AREA_NAME as AR,
  24. ROUND(SUM(RETAIL_STR_SALES_MASTER.GRAND_TOTAL),2) as SALES_VALUE
  25. from retail_str_sales_master, retail_store_area_wise
  26. where retail_store_area_wise.store_id = retail_str_sales_master.store_id
  27. GROUP BY
  28. RETAIL_STORE_AREA_WISE.STORE_NM ,
  29. retail_store_area_wise.area_name,
  30. retail_store_area_wise.area_code,
  31. retail_store_area_wise.town_name
  32. ORDER BY RETAIL_STORE_AREA_WISE.STORE_NM,
  33. retail_store_area_wise.area_name"
  34. query1=dbGetQuery(conn,query)
  35.  
  36. #Dropdown Function
  37.  
  38.  
  39.  
  40. biz = data.frame(
  41.  
  42.  
  43.  
  44. Are=query1$AR,
  45. TOWNNAME=query1$TOWN_N,
  46. Storename=query1$ST,
  47. Salevalue=query1$SALES_VALUE,
  48. stringsAsFactors = FALSE
  49. )
  50.  
  51.  
  52. # connection with dash db
  53. shinyServer(function(input, output, session) {
  54. autoInvalidate <- reactiveTimer(50000, session)
  55. output$Box1 = renderUI(selectInput("yr",label = "select a Area NAME",c(unique(isolate(biz$Are)),"pick one"),"pick one"))
  56.  
  57. output$Box2 = renderUI(
  58.  
  59. if (is.null(input$yr) || input$yr == "pick one"){return()
  60. }else checkboxGroupInput("sector",
  61. "Select a Town_Name",
  62. choices = c(unique(biz$TOWNNAME[which(biz$Are == input$yr)])),
  63. "pick one")
  64. )
  65.  
  66.  
  67.  
  68. subdata1 = reactive(biz[which(biz$TOWNNAME== input$sector),])
  69.  
  70. output$text1 <- renderText({
  71. autoInvalidate()
  72. sprintf("Total value of store per day", input$sector,"sales")
  73. })
  74. output$text2 <- renderText({
  75. autoInvalidate()
  76. sprintf("Total Number of bills per day", input$sector,"sales")
  77.  
  78. })#not showing data as per the multiple checkbox group input working fine on single input select
  79. output$view = DT::renderDataTable({
  80. autoInvalidate()
  81. if(is.null(input$sector) ){return()
  82. } else if (input$sector == "pick one"){return()
  83.  
  84. } else
  85. {
  86. autoInvalidate()
  87.  
  88. subdata1()[,c("TOWNNAME","Storename","Salevalue")]
  89.  
  90.  
  91.  
  92. }
  93. },rownames = FALSE,class = 'cell-border stripe')
  94.  
  95.  
  96.  
  97. output$plot <- renderPlotly({not ploting output as per the multiple checkbox input
  98.  
  99. autoInvalidate()
  100. if (is.null(input$sector)){return()
  101. } else if(input$sector == "pick one") { return()
  102. } else p <- ggplot(data=subdata1() ,aes(x =Storename, y = Salevalue,group=Storename),environment=environment())+ geom_histogram(stat = "identity",aes(fill = type),fill = "blue")+
  103.  
  104. geom_smooth() + ggtitle("ggplot")
  105.  
  106. print(p + theme(axis.text.x =
  107. element_text(size = 10,angle = 45,hjust = 1,vjust = 1))) })
  108. })
  109.  
  110. library(RJDBC)
  111. library(dplyr)
  112. library(shiny)
  113. library(ggplot2)
  114. library(scales)
  115. library(shinydashboard)
  116. library(gridExtra)
  117. library(DT)
  118. library(ggthemes)
  119. library(plotly)
  120.  
  121. sidebarMenu(menuItem("Per Day Sales", tabName = "root", icon = icon("calendar"),uiOutput("Box1"),
  122. uiOutput("Box2")
  123.  
  124. ))
  125. ),
  126. dashboardBody(
  127.  
  128. fluidPage(
  129.  
  130. displaying output of the ggplot
  131. fluidRow(
  132.  
  133.  
  134.  
  135. box(
  136. width = 20, status = "info", solidHeader = TRUE,
  137. title = textOutput("text1"),
  138. plotlyOutput(paste('plot'))),
  139.  
  140.  
  141.  
  142.  
  143. #data table output displaying here
  144. box(
  145. width = 8, status = "info", solidHeader = TRUE,
  146. title = "STORE SALES PER MONTH ",
  147. dataTableOutput("view")
  148.  
  149. )
  150.  
  151. )
  152.  
  153. )
  154.  
  155. )
  156. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement