Skip to content

Instantly share code, notes, and snippets.

@ryanbthomas
Last active July 21, 2023 00:30
Show Gist options
  • Save ryanbthomas/dbf5422081458686a71eab5ef3425189 to your computer and use it in GitHub Desktop.
Save ryanbthomas/dbf5422081458686a71eab5ef3425189 to your computer and use it in GitHub Desktop.
Replace body with javascript
library(shiny)
prepare_party <- function() {
tags$script(
HTML('
function replaceBody() {
document.body.innerHTML = "<h1 style=\\"font-family: Gothic Sans; font-size: 20pt; color: blue;\\">HAPPY BIRTHDAY</h1>";
};
')
)
}
party_time <- function() {
shinyjs::runjs("replaceBody();")
}
ui <- fluidPage(
tags$head(
shinyjs::useShinyjs(),
prepare_party()
),
actionButton("testButton", "Celebrate"),
tags$h1("no party =(")
)
server <- function(input, output, session) {
observeEvent(input$testButton, {
message("Staring party")
party_time()
})
}
shinyApp(ui, server)
@ryanbthomas
Copy link
Author

Note you'll need to run the shiny app in the browser to see the effect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment