Shiny error when generating HTML

3

I'm trying to "create a probability calculator for Normal and Binomial distributions, but this is giving some error when it generates HTML." .Select the codes below.

PS: Would it be possible to exchange mi and sigma for Greek letters?

library(shiny)

ui<-fluidPage(
titlePanel("Calculadora"),  
sidebarLayout(

sidebarPanel(
  selectInput(inputId="dist",
    label="Escolha sua distribuição:",
    choices=c("Binomial"="bin","Normal"="normal"),selected = "bin"),
    sliderInput(inputId="x",label="Escolha o valor de X:",
     min=0,max=50,step = 1,value = 10),
     conditionalPanel(condition = "input.dist=='bin'",
    sliderInput(inputId = "n",label = "Escolha o valor de N:",
     min=0,max=50,step=1,value=25),
    sliderInput(inputId ="p",label="Escolha o valor de P",
      min=0,max = 1,value=0.5)),
    conditionalPanel(condition = "input.dist=='normal'",
    sliderInput(inputId = "s",label = "Escolha o valor de sigma",
      min=0,max=50,step=1,value=25),
    sliderInput(inputId ="m",label="Escolha o valor de mi",
     min=0,max=50,step=1,value=25))
    ),
    mainPanel(textOutput("text_calc"))
  )
)

server <- function(input, output) {
  output$text_calc<-renderPrint({
    if (input$dist=="bin"){
      N<-input$n
      P<-input$p
      k<-input$x
      D<-pbinom(k,N,P)
      paste("Probabilidade pedida:", D)
    }
    if (input$dist=="normal"){
      S<-input$s
      M<-input$m
      k<-input$x
      D<-pnorm(k,M,S)
      paste("Probabilidade pedida:", D)
    }
  }
)

}

shinyApp(ui,server)
    
asked by anonymous 06.05.2018 / 15:04

1 answer

3

Apparently the problem was in the two if threaded. I took one of them and replaced with else . It's okay now.

If it is in your interest to expand this calculator for more distributions, just put more else after the second.

Greek letters can be placed using the withMathJax() function, which loads the MathJax library, which is responsible for LaTeX-based math notation. See the second line of ui code to see how I loaded the library. Then look at the sliderInput corresponding to sigma and mi to see how I wrote them with the corresponding Greek letter.

Search for LaTeX to find out how to make other Greek letters and more complex mathematical expressions, such as integrals, partial derivatives and, well, anything else imaginable.

library(shiny)

ui<-fluidPage( titlePanel("Calculadora"),
           withMathJax(),
           sidebarLayout(
             sidebarPanel(
               selectInput(inputId="dist",
                           label="Escolha sua distribuição:",
                           choices=c("Binomial"="bin","Normal"="normal"),selected = "bin"),
               sliderInput(inputId="x",label="Escolha o valor de X:",
                           min=0,max=50,step = 1,value = 10),
               conditionalPanel(condition = "input.dist=='bin'",
                                sliderInput(inputId = "n",label = "Escolha o valor de N:",
                                            min=0,max=50,step=1,value=25),
                                sliderInput(inputId ="p",label="Escolha o valor de P",
                                            min=0,max = 1,value=0.5)),
               conditionalPanel(condition = "input.dist=='normal'",
                                sliderInput(inputId = "s",label = "Escolha o valor de \(\sigma\)",
                                            min=0,max=50,step=1,value=25),
                                sliderInput(inputId ="m",label="Escolha o valor de \(\mu\)",
                                            min=0,max=50,step=1,value=25))
             ),
             mainPanel(textOutput("text_calc"))
           ) )

server <- function(input, output) { 
  output$text_calc<-renderPrint({ 
    if (input$dist=="bin"){ 
      N<-input$n 
      P<-input$p 
      k<-input$x 
      D<-pbinom(k,N,P) 
      paste("Probabilidade pedida:", D) 
      } else { 
        S<-input$s 
        M<-input$m 
        k<-input$x 
        D<-pnorm(k,M,S) 
        paste("Probabilidade pedida:", D) } 
  }
)
}

shinyApp(ui,server)

    
06.05.2018 / 15:30