How do I implement an action button into my html? I am using the server.R and www\index.html way of creating a ui fully with html. Here is what I have right now:
From what I understand, this would mean that observeEvent would see that submit_loc value changes, which would then trigger it. However this does not seem to work either, and I am not sure why. This is my first time using Shiny, and R in general, so I am not sure if I am missing something obvious. I found that most examples/questions are based around people using ui.R and not index.html, which is what I think is throwing me off, as in ui.R it seems all you need to do is
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.
Thanks for your reply! I managed to get my original working with the messy JS (changing the value of a variable and detecting that) but your way is far cleaner. I saw somewhere that I needed action-button in class but I didn't know about shiny-bound-input, I will try that.
Do you happen to have a link to some documentation about things like shiny-bound-input? It seems like this method of using index.html over ui.R isn't very popular and I've been having some struggles trying to get it to work.
Unfortunately, I'm not aware of any documentation on Shiny CSS classes. The Shiny docs used to print the HTML markup (which is where I found out about css classes like shiny-bound-input), but it may be easier to create a Shiny app with the elements that you would like to replicate in HTML, and then inspect the HTML markup.
Right, that makes sense. This is my first time using Shiny so I wanted to create my front end with something I was more familiar with, though from now on I will probably learn the ui.R syntax as support and docs seem much more extensive that way.
That's great! You may be interested in the htmltools package. The tags object allows you to build UIs in a similar method as HTML documents (the tags object is also available via the shiny package). For example, if you wanted to rewrite the index.html file in R using tags, it would look like this.
library(shiny)
ui <- tagList(
tags$head(
tags$title("HTML Button Test")
),
tags$main(
tags$h1("HTML Button Test"),
tags$p("Click the button."),
tags$button(
id = "btn",
class = "shiny-bound-input action-button",
"My Button"
)
)
)
You wouldn't need to add the shared assets as this is handled by Shiny. Unlike HTML markup, you generating the <body> element (i.e, tags$body) isn't required and handled automatically by Shiny. Doing so will render a nested <body> element