Adding an image to Shiny action button

Viewed 12371

I have a shiny action button but instead of font I wish to display an image. i have used tags$button for the action button. This displays a small grey box. instead i wish to display a "power" button.

 fluidRow(
      column(4,offset=11,
        tags$button(
        id = "reset_button",
        class="btn action-button"

        ))),

Thank you!

2 Answers

Here is another simple solution that worked for me:

actionButton(inputId = "A.button", label = NULL, style = "width: 50px; height: 50px;
background: url('MyImage.png');  background-size: cover; background-position: center;")

the image should be in the www folder inside the app's folder, background size in this case fits image to button size, alternatively you can use background-repeat: no-repeat; to make sure the image is not repeated to fill size, center center should center the image vertically and horizontally.

One could in principle also put the image as label, like:

label = img (src="MyImage.png", width="30", height="30"),

However, then the image could stuck out over the edge of the button compared to inserting it as background.

Related