gpt4 book ai didi

r - 使用用户输入、 Shiny 、renderImage 更改图像

转载 作者:行者123 更新时间:2023-12-04 09:41:15 26 4
gpt4 key购买 nike

我有一个应用程序,它根据用户输入显示数据和图片。我的 ui 中有以下代码:

    selectInput("var", 
label = "Choose a penguin to display",
choices = c("Bowie", "Cookie",
"Mango", "Renesme"),
selected = "Bowie"),

dateRangeInput("dates",
"Date range",
start = "2017-06-16",
end = as.character(Sys.Date())),

imageOutput("img1")
),

mainPanel(plotOutput("plot")
)
)
))

我的服务器中的以下内容:
 output$plot <- renderPlot({
penguin <- switch(input$var,
"Bowie" = filter(date_swim, penguin == 'Bowie'),
"Cookie" = filter(date_swim, penguin == 'Cookie'),
"Mango" = filter(date_swim, penguin == 'Mango'),
"Renesme" = filter(date_swim, penguin == 'Renesme'))
getSwim(min = input$dates[1],
max = input$dates[2],
p = penguin)
})

output$img1 <- renderImage({ #This is where the image is set
if(input$var == "Bowie"){
img(src = "Bowie.png", height = 240, width = 300)
}
else if(input$var == "Cookie"){
img(src = "Cookie.png", height = 240, width = 300)
}
else if(input$var == "Renesme"){
img(src = "Renesme.png", height = 240, width = 300)
}
else if(input$var == "Mango"){
img(src = "Mango.png", height = 240, width = 300)
}
})

})

当我运行时,图像应该在哪里我看到错误消息:

character argument vector expected.

最佳答案

我认为这在文档中有点误导,但对于 RenderImage()您要使用 list()功能而不是 img() .我修改了你的 server.R 文件:

download.file("http://dehayf5mhw1h7.cloudfront.net/wp-content/uploads/sites/38/2016/01/18220900/Getty_011816_Bluepenguin.jpg",
destfile = "Bowie.png")
download.file("http://3.bp.blogspot.com/_cBH6cWZr1IU/TUURNp7LADI/AAAAAAAABsY/76UhGhmxjzY/s640/penguin+cookies_0018.jpg",
destfile = "Cookie.png")

function(input, output) {

output$img1 <- renderImage({ #This is where the image is set
if(input$var == "Bowie"){
list(src = "Bowie.png", height = 240, width = 300)
}
else if(input$var == "Cookie"){
list(src = "Cookie.png", height = 240, width = 300)
}
else if(input$var == "Renesme"){
list(src = "Renesme.png", height = 240, width = 300)
}
else if(input$var == "Mango"){
list(src = "Mango.png", height = 240, width = 300)
}
})

关于r - 使用用户输入、 Shiny 、renderImage 更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45801594/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com