过去在此站点上发布的类似问题并不能提供足够的答案:通过app.R运行应用程序的解决方案对我来说并不能解决问题,图片仍然无法显示
:将图像添加到主面板中,都从Web的文档尝试(将图像转换为Web链接)。
输出的外观:https://cdn1.imggmi.com/uploads/2019/4/24/d65ae8a21decc6adb1d14db9a3e9bf75-full.png
有人知道解决方案吗?如前所述,通过app.R运行应用程序不起作用,输出保持不变。
=OFFSET(B6;
MATCH(A2;Producten!$A:$A;0)-1;1;COUNTIF(Producten!$A:$A;A2);1)
答案 0 :(得分:0)
您应该在服务器端抛出创建图像的代码,将其封装在您已命名的renderPlot({})函数中,然后在“ distPlot” plotOutput之后绘制输出。我无法使用您的img(src = ...)代码,因此我使用了在功能上与此相同的栅格图。一个缩小的示例如下:
library(shiny)
library(png)
ui <- fluidPage(
mainPanel(
plotOutput(outputId = "png")
)
)
server <- function(input, output) {
output$png <- renderPlot({
pic = readPNG('path/to/image.png')
plot.new()
grid::grid.raster(pic)
})
}
shinyApp(ui = ui, server = server)
将其放入您的代码中会得到:
library(shiny)
library(png)
# See above for the definitions of ui and server
library(shiny)
library(png)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# App title ----
titlePanel("Hello Shiny!"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Slider for the number of bins ----
sliderInput(inputId = "bins",
label = "Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Histogram ----
plotOutput(outputId = "distPlot"),
###Changed code here
plotOutput(outputId = "png")
##output: png image
)
)
)
server <- function(input, output) {
# Histogram of the Old Faithful Geyser Data ----
# with requested number of bins
# This expression that generates a histogram is wrapped in a call
# to renderPlot to indicate that:
#
# 1. It is "reactive" and therefore should be automatically
# re-executed when inputs (input$bins) change
# 2. Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful$waiting
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = "#75AADB", border = "white",
xlab = "Waiting time to next eruption (in mins)",
main = "Histogram of waiting times")
})
###New function
output$png <- renderPlot({
pic = readPNG('path/to/image.png')
plot.new()
grid::grid.raster(pic)
})
}
shinyApp(ui = ui, server = server
)
...并显示: