如何在radioGroupButtons的按钮之间获得更多空间并包含图标

问题描述 投票:0回答:1

我正在使用ShinyWidgets软件包的'radioGroupButtons',并使用选项personal = TRUE。按钮紧密并排放置。

我有两个问题。是否可以在按钮之间获得更多的空间?也可以在按钮标签前面加上一个图标(Glyphicon,Awesome字体)吗?

如果看起来像这样,那就太好了:

enter image description here

我的代码如下:

library(shiny)
library(shinyjs)
library(shinyWidgets)

ui <- fluidPage(
  useShinyjs(),

  radioGroupButtons(
    inputId = "id000",
    label = NULL,
    choices = c("Text",  "File", "Web"),
    individual = TRUE,
    selected = character(0))
)

server <- function(input, output, session)
{
  observeEvent(input$id000, alert(input$id000), ignoreInit = TRUE)
}

shinyApp(ui = ui, server = server)
shiny icons glyphicons shinywidgets
1个回答
0
投票

这应该起作用:

library(shiny)
library(shinyjs)
library(shinyWidgets)

ui <- fluidPage(
  useShinyjs(),
  tags$head(tags$style('.btn-group{ margin-left: 15px;}')),  # add the spacing
  icon(NULL),  # need a call to icon to attach some dependencies; probably a better solution exists
  radioGroupButtons(
    inputId = "id000",
    label = NULL,
    choices = c(`<i class='fas fa-font'></i> Text` = "Text",
                `<i class='far fa-file-alt'></i> File` = "File", 
                `<i class='fas fa-globe-americas'></i> Web` = "Web"),
    individual = TRUE,
    selected = character(0))
)

server <- function(input, output, session)
{
  observeEvent(input$id000, alert(input$id000), ignoreInit = TRUE)
}

shinyApp(ui = ui, server = server)
© www.soinside.com 2019 - 2024. All rights reserved.