簡體   English   中英

R閃亮反應顯示列表中的圖像

[英]R Shiny Reactively Display an Image from a list

我試圖在R Shiny應用程序中以反應方式顯示列表中的圖像。

我的應用程序的“ www”目錄中存儲了許多.tiff圖像。 它們遵循OHC_130.tiff,OHC_131.tiff,OHC_132.tiff,IHC_133.tiff,Deiter_134.tiff,OHC_135.tiff等命名約定。

我也有一個包含所有這些名稱的向量

ImgID_Vector <- as.vector(c("OHC_130", "OHC_131", "OHC_132", "IHC_133", "Deiter_134", "OHC_135")

我想創建一個這樣的可選輸入下拉列表,用戶可以在其中選擇圖像,然后單擊“提交”按鈕以使圖像顯示在下面。 我已經為ui.r進行了設置,但是我不確定如何使它在服務器端工作。

#ui.r
library(shiny)
library(shinydashboard)

dashboardBody(
  tabItems(
    tabItem(tabName = "dt",
          h2("Select an image"),
          fluidRow(
            box(title="This is a searchable database of images", solidHeader = TRUE,status = "primary"),
            selectInput("input$ImageIDVariable1", label = h4("Enter your image of interest"), choices = (ImgID_Vector), multiple = TRUE),
            submitButton("Submit"),
            imageOutput("ImageID_Image")
          )
)
)

從概念上講,我知道在服務器端,我需要將UI端的用戶輸入連接到“ www”文件夾中的實際圖像。 我應該能夠使用反應性輸入和我認為的renderImage做到這一點。 但是我不確定如何編寫render image命令來獲得所需的結果。

#server.r

#This is the data that contains the choices for the dropdown menu
ImgID_Vector <- readRDS("ImgID_Vector.RDS")

shinyServer(function(input, output) {
# This is where I am struggling, with the render image command
output$ImageID_Image <- renderImage({
    filename <- normalizePath(file.path('./www',
                          paste(input$ImageIDVariable1, '.tiff', sep='')))
    list(src = filename)
  }, deleteFile = FALSE)
}

#This is where I have the reactive input variable
ImageIDVariable1 <- reactive({input$ImageIDVariable1})

})

謝謝你的幫助!

您好, selectInput參數inputId是錯誤的,它應該是"ImageIDVariable1" ,而不是input$ImageIDVariable1

在ui.R中:

selectInput(inputId = "ImageIDVariable1", label = h4("Enter your image of interest")

在server.R中

input$ImageIDVariable1

此外:

您應該在名為global.R的腳本中至少使用ui.R

ImgID_Vector <- readRDS("ImgID_Vector.RDS")

並且您不應該使用multiple = TRUE因為renderImage一次只能渲染一個圖像。

並且您應該默認放置一個選擇的選項,如果沒有,則renderImage將搜索不存在的圖像。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM