R闪亮-图像不出现 [英] R shiny - image does not appear
问题描述
我正在尝试在闪亮的页面上插入徽标.
I am trying to insert a logo on my shiny page.
以下是可重现的示例:
app.R文件:
setwd(".../shinyApp")
source("ui.R")
source("server.R")
shinyApp(ui, server)
setwd(".../shinyApp")
source("ui.R")
source("server.R")
shinyApp(ui, server)
我使用runApp按钮运行应用程序
I use the runApp button to run the app
ui.R文件:
ui <- shinyUI(fluidPage(
titlePanel("Blabla"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId="min",
label="Values",
min = 10, max = 100, value = 10,sep=" "),
h6("Done by:"),
img(src='logo.png',height=50,width=50)
),
mainPanel(
h1("Main title"),
p("First paragraph"),
h2("Subtitle"),
p("Second paragraph"),
tableOutput("table")
)
)))
ui <- shinyUI(fluidPage(
titlePanel("Blabla"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId="min",
label="Values",
min = 10, max = 100, value = 10,sep=" "),
h6("Done by:"),
img(src='logo.png',height=50,width=50)
),
mainPanel(
h1("Main title"),
p("First paragraph"),
h2("Subtitle"),
p("Second paragraph"),
tableOutput("table")
)
)))
但是这不起作用...我有一个问号错误,而不是我的徽标,好像R找不到我的图像.问号正好位于我的sidebarPanel中(并且出现文本"Done by").
But this does not work ... I have a question mark error instead of my logo as if R could not find my image. The question mark is rightly located in my sidebarPanel though (and the text "Done by" appears).
由于我在很多地方都读过它是一种解决方案,因此我将其图像放在了www目录中(例如: ).
I have put my image in a www directory since I have read in many places that it was a solution (here for ex: Image not showing in Shiny app R).
我闪亮的应用程序结构如下:
My shiny app structure is the following :
-
一个app.R文件:
an app.R file:
shinyApp目录,其中包含:我的ui.R,我的server.R和包含我的logo.png的www目录
a shinyApp directory containing : my ui.R, my server.R and the www directory which contains my logo.png
我不知道我做错了什么...任何人都可以帮忙吗?非常感谢 !
I have no idea what I have done wrong ... can anyone please help ? Many thanks !
推荐答案
有两种方法可以构建闪亮的应用程序.
There are two ways to build your shiny application.
-
在单个文件中定义ui和服务器,并将其命名为
app.R
library(shiny)
ui <- shinyUI(fluidPage(
titlePanel("Blabla"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId="min",
label="Values",
min = 10, max = 100, value = 10,sep=" "),
h6("Done by:"),
img(src='logo.png',height=50,width=50)
)
)))
server <- function(input, output, session) {
} shinyApp(ui, server)
将ui和服务器定义为单独的页面,并将它们另存为ui.R
和server.R
示例ui.R
页面
ui <- shinyUI(fluidPage(
titlePanel("Blabla"),
sidebarLayout(
sidebarPanel(
sliderInput(inputId="min",
label="Values",
min = 10, max = 100, value = 10,sep=" "),
h6("Done by:"),
img(src='logo.png',height=50,width=50)
)
)))
示例server.R
页面
server <- function(input, output, session) {
}
闪亮的输出
这篇关于R闪亮-图像不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!