R语言 在Shiny bs4Dash中,边栏折叠,但图像为图标,菜单未显示

qcuzuvrc  于 2023-03-20  发布在  其他
关注(0)|答案(1)|浏览(181)

bounty将在3天后过期。回答此问题可获得+250的声誉奖励。Laura正在寻找来自声誉良好的来源的答案

当我折叠侧栏时,每个tabItems菜单的图标都不再可见。
我怎样才能改变css,使其在工具条折叠时显示image/img/icons?

library(bs4Dash)
library(shiny)
library(purrr)

 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()的一个参数来使图标在侧边栏折叠时可见,但是我该怎么做呢?
未折叠:

塌陷:

我希望图标出现在折叠的边栏中。

hyrbngr7

hyrbngr71#

最简单的解决方案是使用icon参数,该参数使用font awesome或glyphicon来添加图标,但选项有限。

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)

要使用自定义图像并使其在折叠时显示出来,使用一个闪亮的行就可以了,而且比构建自定义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)

相关问题