Shinydashboard 侧边栏面板输入字段标签中的内联图标

Inline icon in the label of an input field at the sidebar panel in Shinydashboard

我有一个关于我之前问题的后续问题 ()。

现在我想在侧边栏面板中添加一个单选按钮,并在标签的末尾添加一个图标。这个图标将一个动作 link 弹出框。

我可以像以前一样成功地添加图标和更改图标大小post,只是图标与单选按钮的标签不在同一行。是否可以让他们在同一行?

代码:

# Load the packages
library(shiny)
library(shinydashboard)
library(shinyalert)

# User Interface
ui <- dashboardPage(
  header = dashboardHeader(title = ""),
  sidebar = dashboardSidebar(
    sidebarMenu(
      menuItem(
        text = "Example",
        tabName = "tab1"
      ),
      radioButtons(inputId = "radio", choices = c("Yes", "No"),
                   label = HTML("A Radio Button", "<font size='3'>",
                   as.character(actionLink(inputId = "info4", 
                                           label = "", 
                                           icon = icon("info"))), "</font>"))
    )
  ),
  body = dashboardBody(
    # A call to use the shinyalert package
    useShinyalert(),

    tabItems(
      tabItem(
        tabName = "tab1",
        h2(HTML("This is a title", "<font size='3'>",
                as.character(actionLink(inputId = "info1", 
                                        label = "", 
                                        icon = icon("info"))), "</font>")),
        fluidRow(
          box(
            title = HTML("This is the title of the box", "<font size='3'>",
                         as.character(actionLink(inputId = "info2", 
                                                 label = "", 
                                                 icon = icon("info"))), "</font>"), 
            status = "primary", solidHeader = TRUE,
            selectInput(inputId = "Select", 
                        label = HTML("This is the title of the selectInput", "<font size='3'>", as.character(actionLink(inputId = "info3", 
                                                                                                                        label = "", 
                                                                                                                        icon = icon("info"))), "</font>"
                        ), 
                        choices = 1:3)
          )
        )
      )
    )
  )
)

server <- function(input, output, session){
  observeEvent(input$info1, {
    shinyalert(text = "Info 1", type = "info")
  })
  observeEvent(input$info2, {
    shinyalert(text = "Info 2", type = "info")
  })
  observeEvent(input$info3, {
    shinyalert(text = "Info 3", type = "info")
  })
  observeEvent(input$info4, {
    shinyalert(text = "Info 4", type = "info")
  })
}

# Run the app
shinyApp(ui, server)

您可以通过向 actionLink id 添加 display: inline 样式来实现。 这将覆盖 display: block.

所以就在 sidebar = dashboardSidebar( 之后和 sidebarMenu( 之前添加这一行:

tags$head(
  tags$style(
    HTML("#info4 {
         display: inline;
         margin: 0px;
         }")
  )
),