Shiny中的条件复选框绘图

时间:2016-06-26 11:55:56

标签: r shiny

我有两个复选框组财务和经理。如果财务复选框中的特定值表示选择了2016Q1,并且勾选了经理的复选框,则应用程序应绘制该经理2016Q1会计年度的图表。我已单独为复选框编写逻辑但无法集成。

library(shiny)
library(shinythemes)
ui <- fluidPage(theme = shinytheme("journal"),h1("India-DSI",align="center",style = "font-family: 'Lobster', cursive;font-weight: 500;  line-height: 1.1; color: #4d3a7d;"),
            sidebarLayout(
              sidebarPanel(fileInput('file1', 'Choose file to upload',accept= c('text/csv','text/comma-separated-values','text/tab-separated-values','text/plain','.csv','.tsv')),width=2,

               checkboxGroupInput("fiscal", "Fiscal Quarter:", c("2015Q1","2015Q2","2015Q3","2015Q4","2016Q1"),selected = NULL,inline=FALSE),
                  checkboxGroupInput("manager", "Manager:", c("Kalla,Abhay","Koul,Samir","Pudipeddi,Harinath","Huruli,Sharath"),selected =     NULL,inline = FALSE)
              ),
                  mainPanel({
                    plotOutput("plot")
                  })))

server <- function (input , output  )
{ 
  myread <- function ()  
  { 
    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)
     mydata <- read.csv(inFile$datapath)
    return (mydata)
  }

      ## Quarter filter
    {
       output$plot <- renderPlot({
        x <- data.frame(myread())
        y <- x[x$Fiscal.Quarter == input$fiscal, ]
        resources <- factor(y$Resource.Name)
        stan <- tapply(y$Standard.Hours, resources, sum, na.rm = TRUE)
        bil <- tapply(y$Billable.Hours, resources, sum, na.rm = TRUE)
        bu <- bil*100 / stan
       mp <- barplot (bu, col = colors(27), las = 2, yaxt = "n",xlim=NULL, ylim = c(0,200))
     bu<- round(bu, 2)
     text(mp, bu, labels = bu, pos = 3)
  })

  }
  ## Manager Filter
  {
  output$plot <- renderPlot({
    x <- data.frame(myread())
    y <- x[x$Manager == input$manager, ]
    resources <- factor(y$Resource.Name)
    stan <- tapply(y$Standard.Hours, resources, sum, na.rm = TRUE)
    bil <- tapply(y$Billable.Hours, resources, sum, na.rm = TRUE)
    bu <- bil*100 / stan
    mp <- barplot (bu, col = colors(27), las = 2, yaxt = "n", ylim =     c(0,200))
    bu<- round(bu, 2)
    text(mp, bu, labels = bu, pos = 3)
  })

  }

}
shinyApp(ui=ui ,server=server)

0 个答案:

没有答案