HTML display on R console

Hi everyone,

I would like to know if there is a way to NOT display HTML sentences in R console.

Here is my code, in a tabPanel :

tabPanel(icon = icon("user-circle"), "Welcome Page",
       welcome_html <- tags$html(
                         tags$body(
                         br(),
                         p(h3("Welcome in our tool")),
                         br(),
                         HTML("Using data from... "),
                         br(),
                                       
                         HTML("If you have a problem, contact us on...")
                                       
             )),
                                     
             cat(as.character(welcome_html))
                                   
                                     
),

In R console, there is :

<html>
  <body>
    <br/>
    <p>
      <h3>Welcome in our tool</h3>
    </p>
    <br/>
    Using data from... 
    <br/>
    If you have a problem, contact us on...
  </body>
</html>

Thanks

Hi,

You are using the cat function inside your tabPanel function, which is not how is intended to work. The shiny functions allow you to write HTML in a R friendly way, there is no need to use the cat function. There is no need also to save the html in an R variable, just pass the input to the shiny function. Here is a reproducible code:

library("shiny")

ui <- fluidPage(
  
  # App title ----
  titlePanel("Tabsets"),
  
  # Sidebar layout with input and output definitions ----
  sidebarLayout(
    
    # Sidebar panel for inputs ----
    sidebarPanel(
      
      # Input: Select the random distribution type ----
      radioButtons("dist", "Distribution type:",
                   c("Normal" = "norm",
                     "Uniform" = "unif",
                     "Log-normal" = "lnorm",
                     "Exponential" = "exp")),
      
      # br() element to introduce extra vertical spacing ----
      br(),
      
      # Input: Slider for the number of observations to generate ----
      sliderInput("n",
                  "Number of observations:",
                  value = 500,
                  min = 1,
                  max = 1000)
      
    ),
    
    # Main panel for displaying outputs ----
    mainPanel(
      
      # Output: Tabset w/ plot, summary, and table ----
      tabsetPanel(type = "tabs",
                  tabPanel(icon = icon("user-circle"),
                           "Welcome Page",
                           br(),
                           h3("Welcome to our tool"),
                           br(),
                           "Using data from...",
                           br(),
                           "If you have a problem, contact us on..."
                  ),
                  tabPanel("Plot", plotOutput("plot")),
                  tabPanel("Summary", verbatimTextOutput("summary")),
                  tabPanel("Table", tableOutput("table"))
      )
      
    )
  )
)

# Define server logic for random distribution app ----
server <- function(input, output) {
  
  # Reactive expression to generate the requested distribution ----
  # This is called whenever the inputs change. The output functions
  # defined below then use the value computed from this expression
  d <- reactive({
    dist <- switch(input$dist,
                   norm = rnorm,
                   unif = runif,
                   lnorm = rlnorm,
                   exp = rexp,
                   rnorm)
    
    dist(input$n)
  })
  
  # Generate a plot of the data ----
  # Also uses the inputs to build the plot label. Note that the
  # dependencies on the inputs and the data reactive expression are
  # both tracked, and all expressions are called in the sequence
  # implied by the dependency graph.
  output$plot <- renderPlot({
    dist <- input$dist
    n <- input$n
    
    hist(d(),
         main = paste("r", dist, "(", n, ")", sep = ""),
         col = "#75AADB", border = "white")
  })
  
  # Generate a summary of the data ----
  output$summary <- renderPrint({
    summary(d())
  })
  
  # Generate an HTML table view of the data ----
  output$table <- renderTable({
    d()
  })
  
}

shinyApp(ui, server)
1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.