Folks please help, I am struggling with this since quite sometime. Requirement is to change the plot depending upon the user input. There are 6 main filters and also the plots are divided into two parts. This code is regarding the second part-the outlier graphs.Depending upon the metric type and stats type,in addition to the 6 filters selected by the user, the respective histogram plot and other stats should be displayed. I initially started with using the switch function but somehow could not make sense, so tried if..else within the reactive function.On execution, I am not getting any error, however the plot isn't displayed either.Attaching the code snippet below.
#Install the packages
library(shiny)
#Load the file
nx=read.csv("order_view_sample.csv",header=T,stringsAsFactors=F)
#UI code for inputs
ui=fluidPage(
titlePanel("Perf Dashboard"),
sidebarLayout(
sidebarPanel(
selectInput("RunID","Run ID:",choices=unique(as.character(nx$run_id)),multiple=T),
selectInput("OrdCat","Order Category:",choices=unique(as.character(nx$order_category)),multiple=T),
selectInput("OrdAct","Order Action:",choices=unique(as.character(nx$order_action)),multiple=T),
selectInput("OrdCon","Order Contract:",choices=unique(as.character(nx$order_contract)),multiple=T),
selectInput("OrdTyp","Order Type:",choices=unique(as.character(nx$order_types)),multiple=T),
selectInput("UsrTyp","User Type:",choices=unique(as.character(nx$user_type)),multiple=T)
),
mainPanel(
tabsetPanel(
tabPanel("Regular Graphs",selectInput("MetTyp","Metric Type:",choices=c("Ln","Thp","Both")),radioButtons("PlotTyp","Graph Type:",list("Lineplot","Barplot")),plotOutput("regplot")),
tabPanel("Outlier Graphs",selectInput("MetTyp","Metric Type:",choices=c("Ln","Thp")),radioButtons("StatTyp","Stats Type:",list("MeanSig","MADSig")),plotOutput("outplot"))
))))
#Server code for outputs
server=function(input,output) {
mydata=reactive({
subset(input$StatTyp,nx$run_id==input$RunID & nx$order_category==input$OrdCat & nx$order_action==input$OrdAct & nx$order_contract==input$OrdCon & nx$order_types==input$OrdTyp & nx$user_type==input$UsrTyp)
})
statsType=reactive({
output$outplot=renderPlot({
statsType()(mydata())
if(input$StatTyp=="MeanSig") {
hist(mydata[nx$Total.Order.Confirmed],main="Mean based Thp",xlab="Thp",prob=T,border="white",xlim=c(-30,50))
curve(dnorm(x,mean(mydata),sd(mydata)),lwd=2,add=T)
abline(v=mean(mydata),col="violet",lwd=10)
abline(v=sd(mydata),col="brown",lwd=4)
abline(v=median(mydata),col="pink",lwd=5)
rect(xleft=mean(mydata)-sd(mydata),ybottom=mean(mydata)-sd(mydata),xright=mean(mydata)+sd(mydata),ytop=mean(mydata)+sd(mydata),lwd=2,lty=2,border="yellow")
rect(xleft=mean(mydata)-2*sd(mydata),ybottom=mean(mydata)-2*sd(mydata),xright=mean(mydata)+2*sd(mydata),ytop=mean(mydata)+2*sd(mydata),lwd=2,lty=2,border="orange")
rect(xleft=mean(mydata)-3*sd(mydata),ybottom=mean(mydata)-3*sd(mydata),xright=mean(mydata)+3*sd(mydata),ytop=mean(mydata)+3*sd(mydata),lwd=2,lty=2,border="red")
rect(xleft=mean(mydata)-4*sd(mydata),ybottom=mean(mydata)-4*sd(mydata),xright=mean(mydata)+4*sd(mydata),ytop=mean(mydata)+4*sd(mydata),lwd=2,lty=2,border="cyan")
rect(xleft=mean(mydata)-5*sd(mydata),ybottom=mean(mydata)-5*sd(mydata),xright=mean(mydata)+5*sd(mydata),ytop=mean(mydata)+5*sd(mydata),lwd=2,lty=2,border="blue")
rect(xleft=mean(mydata)-6*sd(mydata),ybottom=mean(mydata)-6*sd(mydata),xright=mean(mydata)+6*sd(mydata),ytop=mean(mydata)+6*sd(mydata),lwd=2,lty=2,border="green")
}else{
hist(mydata[nx$Total.Order.Confirmed],main="MAD based Thp",xlab="Thp",prob=T,border="white",xlim=c(-30,50))
curve(dnorm(x,mean(mydata),sd(mydata)),lwd=2,add=T)
abline(v=mad(mydata),col="violet",lwd=10)
abline(v=sd(mydata),col="brown",lwd=4)
abline(v=median(mydata),col="pink",lwd=5)
rect(xleft=mad(mydata)-sd(mydata),ybottom=mad(mydata)-sd(mydata),xright=mad(mydata)+sd(mydata),ytop=mad(mydata)+sd(mydata),lwd=2,lty=2,border="yellow")
rect(xleft=mad(mydata)-2*sd(mydata),ybottom=mad(mydata)-2*sd(mydata),xright=mad(mydata)+2*sd(mydata),ytop=mad(mydata)+2*sd(mydata),lwd=2,lty=2,border="orange")
rect(xleft=mad(mydata)-3*sd(mydata),ybottom=mad(mydata)-3*sd(mydata),xright=mad(mydata)+3*sd(mydata),ytop=mad(mydata)+3*sd(mydata),lwd=2,lty=2,border="red")
rect(xleft=mad(mydata)-4*sd(mydata),ybottom=mad(mydata)-4*sd(mydata),xright=mad(mydata)+4*sd(mydata),ytop=mad(mydata)+4*sd(mydata),lwd=2,lty=2,border="cyan")
rect(xleft=mad(mydata)-5*sd(mydata),ybottom=mad(mydata)-5*sd(mydata),xright=mad(mydata)+5*sd(mydata),ytop=mad(mydata)+5*sd(mydata),lwd=2,lty=2,border="blue")
rect(xleft=mad(mydata)-6*sd(mydata),ybottom=mad(mydata)-6*sd(mydata),xright=mad(mydata)+6*sd(mydata),ytop=mad(mydata)+6*sd(mydata),lwd=2,lty=2,border="green")
}
})
})
}
#Run UI and server codes
shinyApp(ui=ui,server=server)
Please advise as I need to fix this ASAP!
Aucun commentaire:
Enregistrer un commentaire