library(shiny)
library(shinythemes)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(radioButtons(
"fiscal","Quarter:",c("2015Q1","2015Q2","2015Q3","2015Q4","2016Q1"))),
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)
}
plotType <- function(type)
{
switch(type)
Q12015 <- { mydataq1 <- reactive (myread())
x <- reactive(data.frame(mydataq1()))
y <- reactive ({x()[x()$Fiscal.Quarter=="2015Q1",]
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)
})
output$plot <- renderPlot ({ y () })
}
Q22015= { mydataq1 <- reactive (myread())
x <- reactive(data.frame(mydataq1()))
y <- reactive ({x()[x()$Fiscal.Quarter=="2015Q2",]
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)
})
output$plot <- renderPlot ({ y () })
}
Q32015 = { mydataq1 <- reactive (myread())
x <- reactive(data.frame(mydataq1()))
y <- reactive ({x()[x()$Fiscal.Quarter=="2015Q3",]
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)
})
output$plot <- renderPlot ({ y () })
}
Q42015={
mydataq1 <- reactive (myread())
x <- reactive(data.frame(mydataq1()))
y <- reactive ({x()[x()$Fiscal.Quarter=="2015Q4",]
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)
})
output$plot <- renderPlot ({ y () })
}
Q12016={
mydataq1 <- reactive (myread())
x <- reactive(data.frame(mydataq1()))
y <- reactive ({x()[x()$Fiscal.Quarter=="2015Q4",]
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)
})
output$plot <- renderPlot ({ y () })
}
}
plotType(input$fiscal)
}
shinyApp(ui=ui ,server=server)
I have edited my code. Getting the following error now :-
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)**