1

I am having trouble getting Rshiny to do what I want.

I would like the user to select an input from the SelectInput choices and based on that input I would like some Text output that is mathematical notation.

I have tried to implement this with withMathJax(), but I cannot seem to get the code right. Here is some toy code illustrating what I have already:

######################################

ui <-navbarPage(title = "test",
                helpText("Here we select which parameters we want to include in our model"),
                selectInput("torchp",  
                label = h4("Torching Parameters"), 
                choices = list("One parameter", 
                               "Two parameters" ), 
 
                               selected = 1),
mainPanel(
textOutput("torchvalue")
)
)




server <- function(input, output) {

  withMathJax()
  
  torchp_input <- reactive({
    switch(input$torchp,
           "One parameter" = '$$q$$', 
            "Two parameters" = '$$q_m, q_f$$'
           )
    })
  
  output$torchvalue <- renderText({ 
   
    paste("You have selected", torchp_input())
  
  })
  
}


shinyApp(ui = ui, server = server)

###################################

The output I get does not recognise my mathematical notation.

Thanks.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
Fay Frost
  • 11
  • 1
  • Does this answer your question? [Dynamic mathjax formula in Shiny](https://stackoverflow.com/questions/48459729/dynamic-mathjax-formula-in-shiny) – Limey Nov 18 '21 at 11:56
  • Yes! This helped a lot Thanks. The issue was which rendering function I used. In this instance you should use uiOutput and renderUI as follows: In the ui put: ``` uiOutput("torchvalue") ``` In the server use: ``` output$torchvalue <- renderUI({ p( withMathJax("you have selected", torchp_input())) }) ``` – Fay Frost Nov 18 '21 at 15:35

1 Answers1

0

Discovered an answer thanks to help in the comments by @Limey.

The issue was which rendering function I used. In this instance you should use uiOutput and renderUI as follows:

  1. In the UI put:

    uiOutput("torchvalue")
    
  2. In the server use:

    output$torchvalue <- renderUI({ p( withMathJax("you have selected", torchp_input())) }) 
    
tdy
  • 36,675
  • 19
  • 86
  • 83
Fay Frost
  • 11
  • 1