header 在 shinydashboard 的 header 中放置按钮时样式不起作用
header style not working when putting a button in the header of shinydashboard
我设法在闪亮的仪表板 header 中放置了一个操作按钮。但是,当使用 tags$li
应用样式时,它仅适用于侧边栏。删除 tags$a
部分时,样式将应用于整个 header。不确定如何修复它,所以 header 中的样式是一致的- 希望在堆栈溢出中得到一些 hint/directions。
我看过这些帖子:
这个问题是我之前问题的延伸:
这是一个代表(下图):
library(shiny)
library(shinydashboard)
library(htmltools)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(
tags$li(class = "dropdown",
tags$a(actionButton(inputId = "email1", label = "",
icon = icon("envelope", lib = "font-awesome")
#Also tried to adjust the width and height of transparent, no luck
# ,
# style='height: 20px;
# background: transparent;
# border: none;
# font-size: 2rem;
# transform: translate(5%, -30%);'
),
href="mailto:have_a_nice_day@yep.com;"),
# has no effect on the main header bar (the header in which button is placed)
tags$style(".main-header {max-height: 20px}"),
tags$style(".main-header .logo {height: 20px;}"),
tags$style(".sidebar-toggle {height: 20px; padding-top: 1px !important;}"),
tags$style(".navbar {min-height:20px !important}")
)
),
dashboardSidebar(
),
dashboardBody()
)
server <- function(input, output){}
shinyApp(ui, server)
非常感谢您的帮助!
如果 header 中没有电子邮件图标,您的代码可以正常工作。试试这个
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
# tags$li(class = "dropdown",
# tags$a(actionButton(inputId = "email1", label = "",
# icon = icon("envelope", lib = "font-awesome")
#
# #Also tried to adjust the width and height of transparent, no luck
# # ,
# # style='height: 20px;
# # background: transparent;
# # border: none;
# # font-size: 2rem;
# # transform: translate(5%, -30%);'
#
# ),
# href="mailto:have_a_nice_day@yep.com;"),
# ),
tags$li(class = "dropdown",
# has effect on the main header bar
tags$style(".main-header {max-height: 20px !important;}"),
tags$style(".main-header .logo {height: 20px !important;}"),
tags$style(".sidebar-toggle {height: 20px; padding-top: 1px !important;}"),
tags$style(".navbar {min-height:20px !important}")
)
),
dashboardSidebar(
# Adjust the sidebar
tags$style(".left-side, .main-sidebar {padding-top: 20px}")
),
dashboardBody()
)
server <- function(input, output){}
shinyApp(ui, server)
这是因为按钮和 a
标签的填充。你可以这样做:
tags$a(actionButton(inputId = "email1", label = "",
icon = icon("envelope", lib = "font-awesome"),
style = "padding-top: 0; padding-bottom: 0;"),
href="mailto:have_a_nice_day@yep.com;",
style = "padding-top: 0; padding-bottom: 0;")
如果您不使用操作按钮,最好这样做:
library(fontawesome)
和
tags$li(class = "dropdown",
tags$a(fa("envelope"),
href="mailto:have_a_nice_day@yep.com;",
style = "padding-top: 0; padding-bottom: 0;"),
我设法在闪亮的仪表板 header 中放置了一个操作按钮。但是,当使用 tags$li
应用样式时,它仅适用于侧边栏。删除 tags$a
部分时,样式将应用于整个 header。不确定如何修复它,所以 header 中的样式是一致的- 希望在堆栈溢出中得到一些 hint/directions。
我看过这些帖子:
这个问题是我之前问题的延伸:
这是一个代表(下图):
library(shiny)
library(shinydashboard)
library(htmltools)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(
tags$li(class = "dropdown",
tags$a(actionButton(inputId = "email1", label = "",
icon = icon("envelope", lib = "font-awesome")
#Also tried to adjust the width and height of transparent, no luck
# ,
# style='height: 20px;
# background: transparent;
# border: none;
# font-size: 2rem;
# transform: translate(5%, -30%);'
),
href="mailto:have_a_nice_day@yep.com;"),
# has no effect on the main header bar (the header in which button is placed)
tags$style(".main-header {max-height: 20px}"),
tags$style(".main-header .logo {height: 20px;}"),
tags$style(".sidebar-toggle {height: 20px; padding-top: 1px !important;}"),
tags$style(".navbar {min-height:20px !important}")
)
),
dashboardSidebar(
),
dashboardBody()
)
server <- function(input, output){}
shinyApp(ui, server)
非常感谢您的帮助!
如果 header 中没有电子邮件图标,您的代码可以正常工作。试试这个
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(
# tags$li(class = "dropdown",
# tags$a(actionButton(inputId = "email1", label = "",
# icon = icon("envelope", lib = "font-awesome")
#
# #Also tried to adjust the width and height of transparent, no luck
# # ,
# # style='height: 20px;
# # background: transparent;
# # border: none;
# # font-size: 2rem;
# # transform: translate(5%, -30%);'
#
# ),
# href="mailto:have_a_nice_day@yep.com;"),
# ),
tags$li(class = "dropdown",
# has effect on the main header bar
tags$style(".main-header {max-height: 20px !important;}"),
tags$style(".main-header .logo {height: 20px !important;}"),
tags$style(".sidebar-toggle {height: 20px; padding-top: 1px !important;}"),
tags$style(".navbar {min-height:20px !important}")
)
),
dashboardSidebar(
# Adjust the sidebar
tags$style(".left-side, .main-sidebar {padding-top: 20px}")
),
dashboardBody()
)
server <- function(input, output){}
shinyApp(ui, server)
这是因为按钮和 a
标签的填充。你可以这样做:
tags$a(actionButton(inputId = "email1", label = "",
icon = icon("envelope", lib = "font-awesome"),
style = "padding-top: 0; padding-bottom: 0;"),
href="mailto:have_a_nice_day@yep.com;",
style = "padding-top: 0; padding-bottom: 0;")
如果您不使用操作按钮,最好这样做:
library(fontawesome)
和
tags$li(class = "dropdown",
tags$a(fa("envelope"),
href="mailto:have_a_nice_day@yep.com;",
style = "padding-top: 0; padding-bottom: 0;"),