Graph is not exiting in output

Asked

Viewed 65 times

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 a q application for each n changed in the input is generated a curve with the function placed in the server (the function is in the right place?).

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 making the argument add=TRUE, the R is informed that it needs to add the result of this curve to a graph that has already been plotted. But so far, there’s no chart on your app. Replace this line, which has the code of the first graph to be plotted, with 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 argument add=TRUE. Doing this, the result is the screen below:

inserir a descrição da imagem aqui

  • Thank you so much for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.