对于一个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)
要显示这三个切片,我需要制作三个图像:
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)