如何使用EBImage将本地图像加载到闪亮的应用程序以进行图像分析

阿基米德

我想创建一个闪亮的仪表板应用程序,以使用EBImage进行图像分析。我的疑问是如何使用EBImage包将本地图像加载到应用程序中以进行后验分析。

在互联网上,我看到了如何从EBImage-package的系统文件中加载图像,如下例所示:

library(shiny)
library(EBImage)
library(displayWidget)

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Display widget demo"),

  # Sidebar with a select input for the image
  sidebarLayout(
    sidebarPanel(
      selectInput("image", "Sample image:", list.files(system.file("images", package="EBImage")))
    ),

    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(
        tabPanel("Static display", plotOutput("display")),
        tabPanel("Interactive widget", displayWidgetOutput("widget"))
      )
    )
  )
)

server <- function(input, output) {

  img <- reactive({
    f = system.file("images", input$image, package="EBImage")
    x = readImage(f)
  })

  output$widget <- renderDisplayWidget({
    displayWidget(img())
  })

  output$display <- renderPlot({
    display(img(), method="raster", all=TRUE)
  })
}

# Run the application
shinyApp(ui = ui, server = server)

我知道如何使用此加载本地数据:

DataXLSX <- reactive({
    inFile <- input$fileXLSX

    if (is.null(inFile))
      return(NULL)

    loadXLSX <- read.xlsx(inFile$datapath)
    loadXLSX    
  })

但是我不能对readImage()做同样的事情。一些帮助?谢谢

ole

要在您的应用中启用文件上传,您需要用selectInput("image", ...)控件替换用于从示例文件的预定义列表中选择图像小部件fileInput,并在反应表达式中使用其值img来访问上传文件的本地副本。您还需要防范内部的表达式的执行renderDisplayWidget,并renderPlot通过调用req(img())以延迟的图像显示,直到图像文件被选中并加载。有关完整的工作示例,请参见下文。请注意,R包displayWidget提供的功能已集成到EBImage devel分支中,因此EBImage 4.19.3版本开始不再加载displayWidget

library("shiny")
library("EBImage")# >= 4.19.3

ui <- fluidPage(

  # Application title
  titlePanel("Image display"),

  # Sidebar with a select input for the image
  sidebarLayout(
    sidebarPanel(
      fileInput("image", "Select image")
    ),

    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(
        tabPanel("Static raster", plotOutput("raster")),
        tabPanel("Interactive browser", displayOutput("widget"))
      )
    )
  )

)

server <- function(input, output) {

  img <- reactive({
    f <- input$image
    if (is.null(f))
      return(NULL)        
    readImage(f$datapath)
  })

  output$widget <- renderDisplay({
    req(img())
    display(img())
  })

  output$raster <- renderPlot({
    req(img())
    plot(img(), all=TRUE)
  })

}

# Run the application
shinyApp(ui = ui, server = server)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用knitr进行Markdown设置本地图像的大小?

PWA应用程序-使用Angular 6将图像和视频存储在本地存储中

如何部署使用本地数据的闪亮应用程序

仅在将数据加载到闪亮的应用程序中时显示框

无法从Rails应用程序将图像加载到电子邮件中

开发角度应用程序时用户本地图像

使用Webpack加载本地图像

离子iOS混合应用程序如何在没有CORS问题的情况下将图像加载到画布中

在Shinyapps.io上部署后,我的闪亮应用程序不会加载图像,但是在本地完全可以正常运行

将图像从文件系统下载到kivy应用程序

如何从下拉列表将图像上传到闪亮的应用程序

如何使用按钮将图像加载到Kivy窗口中?

如何将本地图像加载到按钮中

如何在使用Javascript将图像加载到Chrome中时对它们进行计数?

如何使用图像发布应用程序

如何使用C#进行for循环以将图像加载到我的应用程序中?

使用angular时如何将视图加载到MVC应用程序中

如何使Dicom图像分析应用程序的.m与platfom独立

如何异步加载本地图像?

在应用程序外按住“睡眠/唤醒”和“主页”按钮进行屏幕截图时,如何获取应用程序的本地通知“使用应用程序打开图像”

将本地图像拖到我的应用程序时,QGraphicsView拖放操作不起作用

如何使用 SystemJS 将 Angular 4 加载到 AngularJS 应用程序中?

没有 img(src()) 的闪亮应用程序中的本地图像?

UWP 应用程序:将图像从文件夹加载到图库而不锁定 .Net Core 中的文件

在 spring-boot 应用程序中,如何将静态内容(例如图像)从本地文件夹而不是资源文件夹加载到 jsp 中?

如何将本地图像加载到 WebGL 上下文

如何使用 Glide 将 svg 图像加载到图像视图

为什么反应应用程序无法正确加载本地图像

如何将指定的图像资产添加到 pubspec,然后将图像加载到 AssetImage 以供应用程序展示?