Graph is not outputting

2
library(shiny)

ui <- fluidPage(

  titlePanel("Funcao Poder"),

  sidebarLayout(
    sidebarPanel(
      sliderInput("n1",
                  "Tamanho da amostra:",
                  min = 1,
                  max = 50,
                  value = 30),
      sliderInput("n2",
                  "Tamanho da amostra:",
                  min = 1,
                  max = 50,
                  value = 30),
      sliderInput("n3",
                  "Tamanho da amostra:",
                  min = 1,
                  max = 50,
                  value = 30),
      sliderInput("n4",
                  "Tamanho da amostra:",
                  min = 1,
                  max = 50,
                  value = 30)
    ),

    mainPanel(
      plotOutput("p1")
    )
  )
)

server <- function(input, output) {
  output$p1 <- renderPlot({
    poder.media = function(n,mu){
      k = qnorm(1-0.05,50,sqrt(25/n))
      prob = 1 - pnorm(k, mu, sqrt(25/n))
      return(prob)
    }
    n <- input$n1
    curve(poder.media(n,x),40,60,xlab=expression(mu),ylab = "Poder",add=TRUE,col="red")
    nn <- input$n2
    curve(poder.media(nn,x),40,60,xlab=expression(mu),ylab = "Poder",add=TRUE,col="blue")
    nnn <- input$n3
    curve(poder.media(nnn,x),40,60,xlab=expression(mu),ylab = "Poder",add=TRUE,col="green")
    nnnn <- input$n4
    curve(poder.media(nnnn,x),40,60,xlab=expression(mu),ylab = "Poder",add=TRUE,col="yellow")

  })
}

shinyApp(ui = ui, server = server)

I would like to generate an application q for each% change of% in the input to generate a curve with the function placed on the server (the function is in the right place?).

    
asked by anonymous 21.06.2018 / 00:24

1 answer

3

The problem is on the line

curve(poder.media(n,x),40,60,xlab=expression(mu),ylab = "Poder",add=TRUE,col="red")

When you put the add=TRUE argument, R is informed that it needs to add the result of this curve to a chart that has already been plotted. But so far, there is no chart in your application. Replace this line, which has the code of the first chart to be plotted, by the line below:

curve(poder.media(n,x),40,60,xlab=expression(mu),ylab = "Poder",col="red")

The only difference between them is the exclusion of the add=TRUE argument. Doing this, the result is the screen below:

    
21.06.2018 / 13:15