-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.R
74 lines (66 loc) · 1.87 KB
/
app.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
library(shiny)
library(RNifti)
library(shinythemes)
library(shinyWidgets)
library(markdown)
source("lazyr.R")
source("interactive.R")
source("animation.R")
read_img_as_array <- function(path) {
img_raw <- RNifti::readNifti(path)
if (length(dim(img_raw)) == 3) return(img_raw[,,])
return(img_raw[,,,])
}
ui <- navbarPage(
"Shiny MRI",
theme = shinytheme("cyborg"),
tabPanel(
"Home",
fluidRow(
column(3, selectInput(
"demo_dt", "Choose a Demo Data", choices = c(
"3D Brain MRI" = "data/3d_t1w.nii.gz",
"4D Brain fMRI" = "data/4d_fmri.nii.gz"
)
)),
column(1, h5("Or"), class = "text-center", style = "padding-top: 15px;"),
column(4, fileInput("your_dt", "Upload a .nii .nii.gz")),
column(1, h2("|"), class = "text-center",
style = "margin-top: -5px; "),
column(3, shinyWidgets::switchInput(
"interactive", "Interactive", onStatus = "success"
), style = "padding-top: 25px;")
),
uiOutput("raster_panel")
),
tabPanel(
"About",
includeMarkdown("about.md")
)
)
server <- function(input, output, session) {
options(shiny.maxRequestSize = 500*1024^2)
app_dt <- reactive({
if (is.null(input$your_dt)) {
out <- read_img_as_array(input$demo_dt)
} else {
datapath <- input$your_dt$datapath
if (tools::file_ext(datapath) == "gz") {
datapath <- sub("gz$", "nii.gz", datapath)
file.rename(input$your_dt$datapath, datapath)
}
out <- read_img_as_array(datapath)
}
return(out)
})
output$raster_panel <- renderUI({
if (input$interactive) {
callModule(raster3d_interactive_Module, "mri_3d", im = app_dt)
raster3d_interactive_UI("mri_3d")
} else {
callModule(raster3d_animation_Module, "mri_3d", im = app_dt)
raster3d_animation_UI("mri_3d")
}
})
}
shinyApp(ui, server)