Guest User

Untitled

a guest
Mar 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. ui <-navbarPage("Calculator",
  2. tabPanel("Cal 1", fluidPage(
  3. headerPanel("Calculation 1"),
  4. sidebarLayout(
  5. sidebarPanel(selectInput("Segment","Select Segment",list("Micro"="Micro","PF"="PF","Retail"="Retail",
  6. "Corporate"="Corporate"))
  7. ),
  8.  
  9. mainPanel(
  10. actionButton("Run_1","Run 1"),
  11. actionButton("Summary", "Summary"),
  12. hr(),
  13. tableOutput("variable"),
  14. plotOutput("plot1"),
  15. plotOutput("plot2"),
  16. verbatimTextOutput("Finish_1")
  17. )))),
  18. tabPanel("Cal 2", fluidPage(headerPanel("Calculation 2"),
  19. sidebarLayout(
  20. sidebarPanel(textInput("CustomerId","Enter Customer ID",value = NULL),
  21. submitButton(text = "Submit")
  22. ),
  23.  
  24. mainPanel(
  25. actionButton("Run_2","Run 2"),
  26. tableOutput("Variable"),
  27. verbatimTextOutput("Finish_2")
  28.  
  29. )))),
  30. )
  31.  
  32. server <- function(input, output) {
  33. model <- reactiveValues(Data=NULL)
  34. observeEvent(input$Run_1,{
  35. model$Finish_1<-
  36. ##### Run Codes 1##########
  37. })
  38. output$Finish_1<-renderPrint({
  39. model$Finish_1
  40. print("Calculation 1 Finished")
  41. })
  42.  
  43. ####table1 is a table created during run of above codes
  44. observeEvent(input$Summary,{
  45. model$plot1<-ggplot(table1,aes(x=Stage,y=`Number`,label=`Number of Cust.`))+
  46. geom_bar(stat = "identity",width=0.7, fill = "#FF6667")+
  47. geom_text(size = 6, position = position_stack(vjust = 0.5))+ggtitle("Stage")
  48.  
  49. })
  50. output$plot1 <- renderPlot({
  51. model$plot1
  52. })
  53. observeEvent(input$Segment,{
  54. model$plot2<-ggplot(filter(table,Segment==input$Segment), aes(Stage, `Number of Cust`,label=`Number of Cust`)) +
  55. geom_bar(aes(fill = Stage), position = "dodge", stat="identity")+ggtitle(input$Segment)+
  56. geom_text(size = 6, position = position_stack(vjust = 0.5))
  57.  
  58. })
  59. output$plot2<-renderPlot({
  60. model$plot2
  61. })
  62. model1 <- reactiveValues(Data=NULL)
  63.  
  64. observeEvent(input$Run_2,{
  65. model1$Finish_2<-
  66.  
  67. ##### Run Codes 2####################
  68. })
  69. output$Finish_2<-renderPrint({
  70. model1$Finish_2
  71. print("Calculation 2 Finished")
  72. })
  73. observeEvent(input$CustomerId,{
  74. model1$Variable<-which(total3$CUSTOMER_ID==input$CustomerId)
  75. })
  76. ####total3 is a table
  77.  
  78. output$Variable = renderTable({
  79. total3[model1$Variable(), ] #use the search.critera() reactive to determine rows to display
  80. })
  81. }
Add Comment
Please, Sign In to add comment