Koffi Frederic Sessie
Koffi Frederic Sessie

Reputation: 71

Render mathematic equations/symbols in formattable (like null and alternative hypothesis H0 and Ha)

Good morning. Please how to render mathematic equations like null and alternative hypothesis in formattable? The code is just a minimal example

Ui part

sliderInput("significance",strong("Significance level :"),min = 0,max = 0.2,value = 0.10),
withMathJax(), formattableOutput("our_result")

server part

output$our_result <- renderFormattable({
        dt3_new <- data.frame(close = c(0.004, 4.05),
                              junior= c(2.001, 0.00007891),
                              child = c(4.5, 0.007891),
                              Lala= c(0.001, 0.00007891))
        
        my_result1 <- as.data.frame(matrix(NA, ncol = 4, nrow = 2))
        for ( i in 1 : 4){
          if (is.numeric(dt3_new[[1, i]])){
            if (as.numeric(dt3_new[[1, i]]) > as.numeric(input$significance) ) {
              my_result1[[1, i]] <- "$$H_0$$ accepted, we can assume normality"
            } else {my_result1[[1, i]] <- "$$H_0$$ denied, the data is not normaly distributed"}
          } else {
            my_result1[[1, i]] <- "Test can not be apply because the sample is very small"
          }
          
          if (is.numeric(dt3_new[[2, i]])){
            if (as.numeric(dt3_new[[2, i]]) > as.numeric(input$significance) ) {
              my_result1[[2, i]] <- paste0("\\( H_0\\) accepted; the sample distribution is not stationary") 
            } else {my_result1[[2, i]] <- paste0("\\( H_0\\) denied; the sample distribution is stationary")}
          } else {
            my_result1[[2, i]] <- "Test can not be apply because the sample is very small"
          }
        }
        
      })

My output is not what i'm expecting

The new output after using $$H_0$$ in the script enter image description here

Upvotes: 1

Views: 313

Answers (1)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84599

Use some dollars for the MathJax code:

library(shiny)
library(formattable)
ui <- fluidPage(
  withMathJax(),
  formattableOutput("ftable")
)
server <- function(input, output){
  output$ftable <- renderFormattable({
    formattable(data.frame(x = "$$H_0$$"))
  })
}
shinyApp(ui, server)

Upvotes: 2

Related Questions