我是Shiny
个应用程序的新手,但我设法构建了一个界面,允许我根据可以在网址上找到的图像从图像网址列表中进行 Select .当我在RStudio
上执行Run App
时,该应用程序运行良好,但一旦我try 从外部功能调用它,图像就不再显示(仅显示缩略图).由于脚本相当长,我在进行了一些调试后设法在基于shiny 项目示例的MRE上重新创建了效果.
library(shiny)
app_ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins and an image
sidebarLayout(
sidebarPanel(
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30),
# Inserting the image
img(src = "/prova/1.jpg", height = "300px", width = "100%")
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
app_server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white',
xlab = 'Waiting time to next eruption (in mins)',
main = 'Histogram of waiting times')
})
}
# Run the application
app <- shinyApp(ui = app_ui, server = app_server)
如果我有一个不同的R脚本(external.R
),其中我像这样调用文件MainApp.R
中包含的应用程序,图像就会崩溃.
source("path_to_app/MainApp.R")
app
事实上,我注意到了一种更奇怪的行为.如果我先使用Run App
个应用程序,则从外部文件获取图像时也会正确显示.如果我清理环境并try 直接获取来源,图像将不会显示.图像似乎被缓存在某个地方.
我的文件夹 struct 是
Shinyapp
|- MainApp.R
|- external.R
|- www
| |- prova
| |- 1.jpg