我试图将图像添加到我的闪亮应用程序中,但当我运行应用程序时,该图像不想显示。
我已经尝试过这行代码:
ui <- fluidPage(
theme = bs_theme(preset = "spacelab"),
titlePanel(
div(class = "header",
img(src = "Steam_icon_logo.png", class = "logo"), # Logo image
div(class = "title", "Game Recommender") # Title text
),
),
这是我想出的解决方案:
我在主应用程序目录中创建了一个
www
目录并将图像存储在该文件夹中。
我在
img()
函数中定义了图像的高度和宽度,这样它就不会占用所有空间。
这是更正后的代码:
ui <- fluidPage(
theme = bslib::bs_theme(preset = "spacelab"),
titlePanel(
div(class = "header",
img(src = "plot.png", height = 100, width = 150), # Logo image
div(class = "title", "Game Recommender Histogram") # Title text
),
),
现在,图像准确地出现在您想要的位置。如果您愿意,您可以进一步调整
img()
的高度和宽度参数。我希望这有帮助!