请协助在闪亮的应用程序上反应性地显示图像的方法。
但首先我什至很难显示单个图像
尝试过以下方法
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
SelectInput(inputId = "images", label = image),
mainPanel(
image output(image))
Server <- function(input,output){
output$image
}
shinyApp(ui,server)
我收到错误“没有为类型注册处理程序
上述代码会导致错误,并且读取图像被存储为光栅数据,无法像这样使用它
使用了两个函数,经过几次迭代后,这些行似乎完成了工作。
image <- list( image1 = "image1.png",
image2 = "image2.png",
image3 = "image3.png")
ui<- fluidPage(
sidebarLayout
sidebarPanel(
selectInput(inputId= "select", label = "Select Image", choices =c(image1, image2, image3), selected = image1)),
mainPanel(
textOutput("selection")
imageOutput("img"))))
server<- function(input,output){
reactive_data <- reactive({
selected_image = input$select
return (selected_image)
})
output$selection <- renderText(
reactiv_data())
output$img<- renderImage(
image_path <- image[[input$select]]
list(src = image_path, alt= "Alt text",
width = "50%", height = "50%")
}, deleteFile = FALSE)}
shinyApp(ui, server)