r - 如何将图像添加到 shinydashboard menuItem()s?
问题描述
本质上,我想用图像替换每个中的图标。更具体地说,我只需要每个人都有一个图像,然后在它旁边有文字。menuItem()
shinydashboard
menuItem()
这是我尝试过的一些中等成功的尝试(在下面的代码中注释);
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Dashboard MenuItems"),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem(
"Dashboard",
tabName = "dashboard",
## creates a drop down w/ no image
# label = img(src = "logo.png",
# title = "logo", height = "35pt")
## creates a drop down with the images
# `tag$` isn't needed
# tags$img(src = "logo.png",
# title = "logo", height = "35pt")
),
menuItem(
"Not Dashboard",
tabname = "not_dashboard"
)
) # end sidebarMenu
), # end dashboardSidebar
dashboardBody(
fluidRow(
box(
title = "stuff goes here",
width = 12
)
)
) # end dashboardBody
)
server <- function(input, output, session) {
message("You can do it!")
}
shinyApp(ui, server)
我成功地使用带有背景图像的动作按钮来模拟行为,但如果可能的话,我更愿意使用menuItem()
s 找到解决方案。
我希望有一种类似的方法可以将图像添加到背景中menuItem()
或将图像与menuItem()
.
我不擅长使用闪亮的标签。我对 HTML/CSS/JS 或 Bootstrap 知之甚少,大多数时候我可以在这里找到解决方案并破解我想要的方法,但是这个方法让我望而却步。
有任何想法吗?
解决方案
您可以将图像保存在 www 文件夹中,并使用 div 将图像与文本一起包装,如下所示。
ui <- dashboardPage(
dashboardHeader(title = "Dashboard MenuItems"),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem( div(tags$img(src = "YBS.png", width="20px"), "Dashboard2"),
tabName = "dashboard" # , icon=icon("b_icon")
),
menuItem(
div(tags$img(src = "mouse.png", width="35px"),"Not Dashboard"),
tabname = "not_dashboard" #, icon=icon("home")
)
) # end sidebarMenu
), # end dashboardSidebar
dashboardBody(
fluidRow(
box(
title = "stuff goes here",
width = 12
)
)
) # end dashboardBody
)
server <- function(input, output, session) {
message("You can do it!")
}
shinyApp(ui, server)
推荐阅读
- r - 使用 jsonlite 库进行抓取
- c# - 使用反射获取属性值的空验证
- css - 无法更改引导工具提示“箭头”的 CSS
- python-3.x - Python 密码学:不支持 RSA 密钥格式
- angular - Angular/RxJS:带有可观察对象的嵌套服务调用
- forms - 如何删除动态添加的texbox
- kubernetes - minikube 启动失败解决方法清除传递给 kubeadm init 的所有参数
- python - Pandas 根据多列/行条件添加不同的行
- java - Hibernate 无法创建到数据库服务器的连接
- android - 如何将使用过的图像存储到一个可绘制文件夹中以减少 android 应用程序中的内存