我仍然在努力寻找一种在R中交互显示连续图像的方法.

在下面,我将生成一个3D对象mat3d.

mat <- matrix(dnorm(seq(
  from = -10,
  to = 10,
  length.out = 100 * 100
), sd = 5),
c(100, 100))

mat2d <- mat * t(mat)

mat3d <- array(c(mat2d, mat2d * 0.9, mat2d * 0.8), c(100, 100, 3))

image(mat3d[, , 1],
      useRaster = TRUE,
      asp = 1,
      zlim = c(0, 0.01))

我希望能够通过简单地在2D图像下方移动光标来显示mat3d[, , 1]mat3d[, , 2]mat3d[, , k].

我还希望能够切换尺寸,这样我就可以显示mat3d[, 1, ]mat3d[, 2, ]mat3d[, j, ]mat3d[1, , ]mat3d[2, , ]mat3d[i, , ].

我可以在R中使用plotly或Java脚本来获得它吗?

非常感谢您的帮助.

推荐答案

对于一个shiny 的应用程序来说,这是一份很好的工作.这是一个起点.

mat <- matrix(dnorm(seq(
  from = -10,
  to = 10,
  length.out = 100 * 100
), sd = 5),
c(100, 100))

mat2d <- mat * t(mat)

mat3d <- array(c(mat2d, mat2d * 0.9, mat2d * 0.8), c(100, 100, 3))


library(shiny)
ui <- fluidPage(
  fluidRow(
    column(
      12,
      radioButtons(
        "index", label = "Choose the index", 
        choices = c("1", "2", "3"), inline = TRUE
      )
    ),
    column(
      12,
      plotOutput("img")
    )    
  )
)

server <- function(input, output, session) {
  
  output[["img"]] <- renderPlot({
    index <- as.integer(input[["index"]])
    image(mat3d[, , index],
          useRaster = TRUE,
          asp = 1,
          zlim = c(0, 0.01))
  })
}

shinyApp(ui, server)

enter image description here

要显示这三个切片,我需要制作三个图像:

mat <- matrix(dnorm(seq(
  from = -10,
  to = 10,
  length.out = 100 * 100
), sd = 5),
c(100, 100))

mat2d <- mat * t(mat)

mat3d <- array(c(mat2d, mat2d * 0.9, mat2d * 0.8), c(100, 100, 3))

image(mat3d[70, , ],
      useRaster = TRUE,
      asp = 1,
      zlim = c(0, 0.01))

library(shiny)
ui <- fluidPage(
  fluidRow(
    column(
      4,
      numericInput(
        "ix", label = "Slice x", 
        min = 1, max = 100, step = 1, value = 50
      ),
      br(),
      plotOutput("imgx")
    ),
    column(
      4,
      numericInput(
        "iy", label = "Slice y", 
        min = 1, max = 100, step = 1, value = 20
      ),
      br(),
      plotOutput("imgy")
    ),
    column(
      4,
      radioButtons(
        "iz", label = "Slice z", 
        choices = c("1", "2", "3"), inline = TRUE
      ),
      br(),
      plotOutput("imgz")
    )
  )
)

server <- function(input, output, session) {
  
  output[["imgx"]] <- renderPlot({
    index <- input[["ix"]]
    image(mat3d[index, , ],
          useRaster = TRUE,
          asp = 1,
          zlim = c(0, 0.01))
  })
  
  output[["imgy"]] <- renderPlot({
    index <- input[["iy"]]
    image(mat3d[, index, ],
          useRaster = TRUE,
          asp = 1,
          zlim = c(0, 0.01))
  })
  
  output[["imgz"]] <- renderPlot({
    index <- as.integer(input[["iz"]])
    image(mat3d[, , index],
          useRaster = TRUE,
          asp = 1,
          zlim = c(0, 0.01))
  })
  
}

shinyApp(ui, server)

enter image description here

R相关问答推荐

在ubuntu 22.04上更新到R4.4后包安装出现编译错误

无法在我的情节中表现出显着的差异

查找具有平局的多个列的最大值并返回列名或平局 destruct 者NA值

以R中的正确顺序将日期时间字符列转换为posixct

selectInput不返回ALL,并将因子转换为shiny 的数字

如何在编辑列时更新可编辑数据表,并使用该表在Shiny中执行连续计算

在另存为PNG之前隐藏htmlwidget绘图元素

如何同时从多个列表中获取名字?

矩阵的堆叠条形图,条形图上有数字作为标签

Select 季度月值

如何将SAS数据集的列名和列标签同时包含在r中GT表的表首?

将多个变量组合成宽格式

将摘要图添加到facet_WRAP gglot的末尾

数值型数据与字符混合时如何进行绑定

R-使用stri_trans_General()将其音译为德语字母

R try Catch in the loop-跳过缺少的值并创建一个DF,显示跳过的内容

在REST API中使用参数R

将字符变量出现次数不相等的字符框整形为pivot_wider,而不删除重复名称或嵌套字符变量

带查找数据的FCT_REORDER.帧

通过不完全重叠的多个柱连接