I have a shiny app with UI entirely written in HTML and I need the HTML element with specific id to be hidden/shown, depending on whether the data meets specific conditions.
Below is a simplified version of what I already have, I used ShinyJS, but functions show() and hide() don't do anything in my app. What do I need to do in order to make this work? If it's not possible with ShinyJS, what's the other way I can show/hide html elements in a shiny app? Thanks in advance.
app.R
server <- function(input, output) {
library(shinyjs)
useShinyjs(html = TRUE)
data <- reactive({
return("abcde")
})
observe({
if ( data() == "abcde" ) {
hide("visibility-area")
} else {
show("visibility-area")
}
})
output$some-output <- renderPrint({
cat(data())
})
}
shinyApp(ui = htmlTemplate("www/index.html"), server)
www/index.html
<!DOCTYPE html>
<html>
<head>
<script src="shinyjs/inject.js"></script>
<script src="shared/jquery.js" type="text/javascript"></script>
<script src="shared/shiny.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
<title>test</title>
</head>
<body>
<div id="visibility-area">
<p><span id="some-output" class="shiny-text-output"></span></p>
</div>
</body>
</html>
global.R
shiny::addResourcePath("shinyjs", system.file("srcjs", package = "shinyjs"))