当我折叠侧边栏时,没有显示每个TabItems菜单的图标.

如何才能将css更改为一旦折叠侧边栏,就会显示图像/img/图标?

library(bs4Dash)

 ui <- dashboardPage(
    header = dashboardHeader(
      title = dashboardBrand(
        title = "My dashboard",
        color = "primary",
        # href = "https://adminlte.io/themes/v3",
        image = "https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png"
      )
    ),

    sidebar = dashboardSidebar(
      bs4Dash::sidebarMenu(id = "sidebarMenu",

                           map2(
                             c(
                               'Africa',
                               'Americas',
                               'Asia',
                               'Europe',
                               'Oceania'
                             ),
                             1:5,
                             ~
                               bs4Dash::menuItem(
                                 text = p(
                                   class = 'p_sidebar_country',
                                   tags$img(
                                     src ="https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png",
                                     width = '18px',
                                     height = '18px',
                                     style = 'margin-right: .25em;'
                                   ),
                                   paste0(.x)
                                 ),
                                 tabName = paste0('panel_', .y)
                               )
                           ))

    ),

    body = dashboardBody(),

    controlbar = dashboardControlbar(),
    title = "DashboardPage"
  )
  server <- function(input, output) { }


shinyApp(ui, server)

我想我可以使用css,甚至dashboardSidebar()函数的自变量,但如何使用呢?

推荐答案

最简单的解决方案是只使用icon参数,它使用字体棒或字形图标来添加图标,但选项有限.

library(bs4Dash)

ui <- dashboardPage(
  header = dashboardHeader(
    title = dashboardBrand(
      title = "My dashboard",
      color = "primary",
      # href = "https://adminlte.io/themes/v3",
      image = "https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png"
    )
  ),
  
  sidebar = dashboardSidebar(
    bs4Dash::sidebarMenu(id = "sidebarMenu",
                         
                         map2(
                           c(
                             'Africa',
                             'Americas',
                             'Asia',
                             'Europe',
                             'Oceania'
                           ),
                           1:5,
                           ~
                             bs4Dash::menuItem(
                               icon = icon("a"),
                               text = .x,
                               tabName = paste0('panel_', .y)
                             )
                         ))
    
  ),
  
  body = dashboardBody(),
  
  controlbar = dashboardControlbar(),
  title = "DashboardPage"
)
server <- function(input, output) { }
shinyApp(ui, server)

shiny_icon

要使用自定义图像并使其在折叠时显示,使用shiny 的行会起作用,而且比构建自定义css容易得多:

library(bs4Dash)

ui <- dashboardPage(
  header = dashboardHeader(
    title = dashboardBrand(
      title = "My dashboard",
      color = "primary",
      # href = "https://adminlte.io/themes/v3",
      image = "https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png"
    )
  ),
  
  sidebar = dashboardSidebar(
    bs4Dash::sidebarMenu(id = "sidebarMenu",
                         
                         map2(
                           c(
                             'Africa',
                             'Americas',
                             'Asia',
                             'Europe',
                             'Oceania'
                           ),
                           1:5,
                           ~
                             bs4Dash::menuItem(
                               text = 
                                 shiny::fillRow(
                                   tags$img(
                                     src ="https://adminlte.io/themes/v3/dist/img/AdminLTELogo.png",
                                     width = '18px',
                                     height = '18px',
                                     style = 'margin-right: .25em;'
                                   ),
                                   tags$p(
                                     class = 'p_sidebar_country',
                                     paste0(.x)
                                   ),
                                   flex = c(1,4),
                                   height = "18px"
                                ),
                               tabName = paste0('panel_', .y)
                             )
                         ))
    
  ),
  
  body = dashboardBody(),
  
  controlbar = dashboardControlbar(),
  title = "DashboardPage"
)
server <- function(input, output) { }
shinyApp(ui, server)

fill_row

R相关问答推荐

图片中令人惊讶的行为

过滤Expand.Grid的结果

在边界外添加注释或标题

计算R中的威布尔分布的EDF

Highcharter多次钻取不起作用,使用不同方法

如何根据组大小应用条件过滤?

手动打印线型gplot

当两个图层映射到相同的美学时,隐藏一个图层的图例值

如何将移除事件分配给动态创建的按钮?

在组中添加值增加和减少的行

为什么舍入POSIXct会更改能力以匹配等效的POSIXct?

使用整齐的计算(curl -curl )和杂音

线性模型斜率在减少原始数据时提供NA

如何识别倒排的行并在R中删除它们?

如何将使用rhandsontable呈现的表值格式化为百分比,同时保留并显示完整的小数精度?

从多个可选列中选取一个值到一个新列中

根据约束随机填充向量的元素

计算使一组输入值最小化的a、b和c的值

如何在R中创建这些列?

将美学添加到ggploy中的文本标签