I'd like to add a class to the tag at the beginning of the HTML rendered in the shiny application.
For example, use this code to generate a basic app:
library(shiny)
ui <- basicPage()
server <- function(input, output){}
shinyApp(ui, server)
If you inspect the page, you see the html tag at the beginning as:
<html style="overflow: hidden;">
I'd like to make it something like this:
<html class="myclass" style = "overflow: hidden;">
Is there a way to do this without using javascript?
You can use tags$html
for this. tags
contains many more other HTML
tags, you can look for them ?shiny::tags
library(shiny)
ui <- basicPage(
tags$html(class="myclass", style = "overflow: hidden;")
)
server <- function(input, output){}
shinyApp(ui, server)
In answer to a comment:
This doesn't quite do what I want it to. This will add a new html tag inside the page, whereas I want to edit the one that's automatically generated
Are you sure? When I inspect the HTML code I can see that it modified the < html > tag:
You can use the shinyjs
package, it has a function called addClass()
. It does use javascript under the hood so I'm not sure if this is fine for you or not. It'd be like this:
library(shiny)
ui <- basicPage(shinyjs::useShinyjs())
server <- function(input, output){
shinyjs::addClass(class = "myclass", selector = "html")
}
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With