library(shiny)

shinyServer(function(input, output) {
  output$cdf <- renderPlot({

      hypmean <- input$power.mu0
      truemean <- seq(hypmean-2,hypmean+2,length.out=200)

      par(mar=c(4.1,4.1,0.1,0.1))
      plot(c(-1),-1,xlim=range(truemean),ylim=c(0,1),xlab=expression(paste("true mean ",mu)), ylab=expression(paste("power ",beta(mu))))
      if (input$alternative=="two-sided"){
        f <- function(level,n,...){
          lines(truemean,1-pnorm(qnorm(1-level/2)-sqrt(n)*(hypmean-truemean))+pnorm(-qnorm(1-level/2)-sqrt(n)*(hypmean-truemean)),
                ...)
        }
      }
      if (input$alternative=="larger"){
        f <- function(level,n,...){
          lines(truemean,pnorm(-qnorm(1-level)-sqrt(n)*(hypmean-truemean)),
                ...)
        }
      }
      if (input$alternative=="smaller"){
        f <- function(level,n,...){
          lines(truemean,1-pnorm(qnorm(1-level)-sqrt(n)*(hypmean-truemean)),
                ...)
        }
      }
      f(level=input$power.level,n=input$power.n,lty=1,col="blue",lwd=2)
      lines(truemean,rep(input$power.level,length(truemean)),col="darkred",lty=2)
    })
})