【问题标题】:Shiny Title image seems unformatted闪亮的标题图像似乎未格式化
【发布时间】:2021-11-30 02:47:14
【问题描述】:

我正在开发一个闪亮的应用程序,而不是标题,我想使用图像。虽然代码没有引发任何错误并显示了图像的指定区域,但图像并没有显示出来。

代码如下:

# header UI
ui <- navbarPage(title = div(img(src="/Users/atillacolak/Desktop/tafn_logo.png",
                                 height = 60,
                                 style = "margin-top: -14px; padding-right:10px;padding-bottom:10px")),
                 selected = "home",
                 theme = bs_theme(
                     bg = "white",
                     fg = "#ed7117",
                     base_font = font_google("Prompt"),
                     code_font = font_google("JetBrains Mono")),
                 fluid = TRUE,
                 home)

这段代码的结果如下图所示。

如您所见,图像未格式化。这里有什么问题?

【问题讨论】:

    标签: r image user-interface shiny navbar


    【解决方案1】:

    您需要将图像作为静态资源提供给闪亮的网络服务器。

    要么将图像放入www 文件夹(应用文件夹的子目录)并设置src = "/tafn_logo.png",要么使用addResourcePath

    addResourcePath(prefix = "Desktop", directoryPath = "/Users/atillacolak/Desktop")
    

    src 使用前缀:

    img(src="Desktop/tafn_logo.png",
                                     height = 60,
                                     style = "margin-top: -14px; padding-right:10px;padding-bottom:10px")
    

    查看我的相关回答here

    【讨论】:

    • 添加资源路径有效,谢谢
    猜你喜欢
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 2015-09-01
    • 1970-01-01
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多