Adding an image to Shiny action button

前端 未结 2 977
一生所求
一生所求 2020-12-19 08:26

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

2条回答
  •  囚心锁ツ
    2020-12-19 08:47

    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.

提交回复
热议问题