Search code examples
rshinyshinydashboard

format helpText in shinydashboard::box


I have a helpText widget in a shinydashboard box in my shiny app. A helpText outside a shinydashboard::box() can easily be formatted, however, in the box(), new lines as well as other HTML elements, are not respected. please find below my code and the image I currently am getting.

validation_rules_text_cas<-helpText('Please enter one string per line.', # ----
                        "A CAS Registry Number includes up to 10 digits which are separated in 3 hyphens.",
                        '- The first part of the number, starting from the left, has 2 to 7 digits',
                        '- The second part has 2 digits',
                        '- The final part consists of a single check digit.')
validation_rules_text_inchikey<-helpText('Please enter one string per line.',
                                  "International Chemical Identifier KEY validation rules.  InChIKey consists of several distinct components:",
                                  "- 14 characters resulting from a hash of the connectivity information of the InChI,encodes molecular skeleton (connectivity),",
                                  "- followed by a hyphen,",
                                  "- followed by 8 characters resulting from a hash of the remaining layers of the InChI,",
                                  "- Encodes proton positions (tautomers), stereochemistry, isotopomers, reconnected layer,",
                                  "- followed by a single character indicating the kind of InChIKey,",
                                  "- followed by a single character indicating the version of InChI used,",
                                  "- another hyphen,",
                                  "- followed by single character indicating protonation.(Source: Wikipedia).",
                                  "  AAAAAAAAAAAAAA-BBBBBBBBCD-E")

tabPanel("Batch Search", #----
                        fluidRow(column(5),
                                 column(7,# helpText----
                                        box(title=' CAS Validation Rules',width=12,
                                            collapsible = TRUE,
                                            collapsed=TRUE,
                                            status = 'primary',
                                            validation_rules_text_cas
                                          ),
                                        box(title='Inchikey Validation Rules',width=12,
                                            collapsible = TRUE,
                                            collapsed=TRUE,
                                            status = 'primary',
                                            validation_rules_text_inchikey
                                        ),
                                        box(title='SMILES Validation Rules',width=12,
                                            collapsible = TRUE,
                                            collapsed=TRUE,
                                            status = 'primary',
                                            validation_rules_text_smiles
                                        ),
                                        box(title='Validation Rules - OTHER',width=12,
                                            collapsible = TRUE,
                                            collapsed=TRUE,
                                            status = 'primary',
                                            validation_rules_text_other
                                        ))
))
  

enter image description here

How do I add new lines breaks (tags$br()) or new lines (tags$hr())? Thank you


Solution

  • Based on this this answer, you can use renderUI in the server function, and htmlOutput in the ui. So for example:

    output$validrules <- uiOutput({ 
    
              HTML(paste(
              p('Please enter one string per line.'), 
              p("A CAS Registry Number includes up to 10 digits which are separated in 3 hyphens."),
              p('- The first part of the number, starting from the left, has 2 to 7 digits'),
              p('- The second part has 2 digits'),
              p('- The final part consists of a single check digit.')
              ))
        })
    

    Then:

    box(title=' CAS Validation Rules',width=12,
                                 collapsible = TRUE,
                                 collapsed=TRUE,
                                 status = 'primary',
                                 htmlOutput("validrules")
                             )