[英]How do I add an image to shinydashboard menuItem()s?
In essence, I would like to replace the icon in each menuItem()
in a shinydashboard
with an image.本质上,我想用图像替换
shinydashboard
中每个menuItem()
中的图标。 More specifically, I just need each menuItem()
to have an image then text next to it.更具体地说,我只需要每个
menuItem()
都有一个图像,然后是它旁边的文本。
Here's some moderately successful attempts I have tried (commented in code below) ;这是我尝试过的一些中等成功的尝试(在下面的代码中注释) ;
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)
I successfully used action buttons with background images to simulate the behavior, but I would prefer to find a solution using menuItem()
s, if possible.我成功地使用带有背景图像的操作按钮来模拟行为,但如果可能的话,我更愿意使用
menuItem()
找到解决方案。
I was hoping there would be a similar method to add the image to the background of the menuItem()
or concatenate the image with the text within the menuItem()
.我希望有一种类似的方法可以将图像添加到
menuItem()
的背景或将图像与menuItem()
中的文本连接起来。
I am not good with shiny tags.我不擅长 shiny 标签。 I don't really know much about HTML/CSS/JS or Bootstrap, most of the time I can find a solution here and hack my way to what I want, but this one has eluded me.
我对 HTML/CSS/JS 或 Bootstrap 知之甚少,大多数时候我可以在这里找到解决方案并破解我想要的方法,但这个方法让我望而却步。
Any ideas?有任何想法吗?
You can keep your images in the www folder and use a div to wrap the image along with the text as shown below.您可以将图像保存在 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.