dipterix / threeBrain

3D Visualization of Brain MRI
https://dipterix.org/threeBrain/
42 stars 10 forks source link

Shiny functions #4

Closed sergiumocanu closed 4 years ago

sergiumocanu commented 4 years ago

Hi there,

First off, thank you so much for this package. The demo and all the functions are really impressive. I'm working on a shiny app and I'd like to use your package. This is my setup, but it's int working.

In the ui

threejsBrainOutput(outputId = 'brain')

in server

output$brain <- renderBrain({
        brain = threeBrain::freesurfer_brain(
            fs_subject_folder = '~/rave_data/others/three_brain/N27/', subject_name = 'N27',
            additional_surfaces = c('white', 'smoothwm')
        )
        plot( brain )
        })

When I run it, the app just hangs and nothing is displayed. Could you kindly advise? Maybe I'm doing something wrong.

dipterix commented 4 years ago

Hi @sergiumocanu , Sorry for the delayed feed back. Please perform the following checks:

  1. Download Github version (devtools::install_github("dipterix/threeBrain")) as I made several changes.
  2. Whether you have downloaded N27 Collins brain. (you can use function threeBrain::download_N27() to download it automatically.
  3. You can't use RStudio default viewer, it does not have WebGL2 support. You might want to try shinyApp(ui, server, options = list(launch.browser = TRUE)), or use Chrome to open the site.
  4. Whenever a brain is loaded at the first time, threeBrain need to cache FreeSurfer files, which takes time (This is a one-time procedure). Usually you can see progress messages printed out in R's console. Just wait for a minute.
  5. If you have done all the previous steps, try the following example:
library(threeBrain)
library(shiny)

ui <- fluidPage(
  threejsBrainOutput(outputId = 'brain', height = '100vh')
)

server <- function(input, output, session) {

  output$brain <- renderBrain({
    brain = threeBrain::freesurfer_brain(
      fs_subject_folder = '~/rave_data/others/three_brain/N27/', subject_name = 'N27',
      additional_surfaces = c('white', 'smoothwm')
    )
    plot( brain )
  })
}

shinyApp(ui, server, options = list(launch.browser = TRUE))

Here is what R console looks like when loading N27 for the first time:

image

Here's what the viewer looks like image

sergiumocanu commented 4 years ago

Excellent, thank you so much! Works amazing 💯