将图像添加到闪亮的动作按钮 [英] Adding an image to Shiny action button

查看:8
本文介绍了将图像添加到闪亮的动作按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个闪亮的操作按钮,但我希望显示的不是字体,而是图像。我对操作按钮使用了标记$BUTTON。这将显示一个灰色的小方框。相反,我希望显示一个"电源"按钮。

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

        ))),

谢谢!

推荐答案

使用函数icon的参数actionButton()

非常简单
actionButton("goButton", "", icon = icon("play-circle"))

或者,您也可以使用函数icon()将图标添加到按钮代码:

tags$button(
          id = "reset_button",
          class="btn action-button",
          icon("close")

        )

或者您使用img()函数来使用您自己的函数:

    tags$button(
      id = "web_button",
      class = "btn action_button",
      img(src = "http://www.craftech.com/wp-uploads/2015/05/web.png",
               height = "50px")
    )

若要获取更全面的可能图标列表,请查看shiny包的?icon帮助页和See Also部分中的链接。

示例应用:

shinyApp(
  ui = shinyUI(
    fluidPage(
      fluidRow(
        actionButton("goButton", "", icon = icon("play-circle")),
        tags$button(
          id = "reset_button",
          class="btn action-button",
          icon("close")

        ),
        tags$button(
          id = "web_button",
          class = "btn action-button",
          tags$img(src = "http://images.all-free-download.com/images/graphicthumb/button_play_89677.jpg",
                   height = "50px")
        )
      ),
      fluidRow(
        textOutput("text")
      )
    )
  ),
  server = function(input, output, session){
    out <- reactiveVal("Nothing")
    observeEvent(input$goButton,{
      out("Go Pushed")
    })
    observeEvent(input$reset_button,{
      out("Resetted")
    })
    observeEvent(input$web_button,{
      out("From the web")
    })
    output$text <- renderText({out()})
  }
)

这篇关于将图像添加到闪亮的动作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆