You are almost there in the original post. Creating a custom input binding is possible, but could be a bit more work if you need to respond to a button click. To "hook" into the Shiny from vanilla HTML buttons, add the following css class shiny-bound-input action-button
. Here's a small example.
www/index.html
<!DOCTYPE html>
<html>
<head>
<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>HTML Button Test</title>
</head>
<body>
<main>
<h1>HTML Button test</h1>
<p>Click the button.</p>
<button id="btn" class="shiny-bound-input action-button">
My Button
</button>
</main>
</body>
</html>
app.R
library(shiny)
# server: print a message when the button is clicked
server <- function(input, output) {
observeEvent(input$btn, {
print("button clicked")
})
}
# load template
shinyApp(ui = htmlTemplate("www/index.html"), server)