Last active
July 21, 2023 00:30
-
-
Save ryanbthomas/dbf5422081458686a71eab5ef3425189 to your computer and use it in GitHub Desktop.
Replace body with javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note you'll need to run the shiny app in the browser to see the effect