Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render with R-shiny #39

Open
dipterix opened this issue Jun 6, 2022 · 2 comments
Open

Render with R-shiny #39

dipterix opened this issue Jun 6, 2022 · 2 comments
Assignees
Labels
investigate needs some investigation

Comments

@dipterix
Copy link

dipterix commented Jun 6, 2022

Wow, amazing package!

I was trying to incorporate fsbrain into our R-shiny application called RAVE (https://rave.wiki). However, I found that rgl::renderRglwidget cannot render the interactive brain. Instead, fsbrain visualizes the results to xQuartz instead of to the web widget. Would you mind instructing on how I could show them in R-shiny instead of xQuartz?

Thanks : )

library(shiny)
library(fsbrain)

ui <- fluidPage(
  rgl::rglwidgetOutput("viewer")
)

server <- function(input, output, session) {
  output$viewer <- rgl::renderRglwidget({
    subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
    subjects_list = c("subject1", "subject2");
    subject_id = 'subject1';   
    vis.subject.annot(subjects_dir, 'subject1', 'aparc', 'both', views=c('si'));
  })
}

shinyApp(ui, server)
@dfsp-spirit
Copy link
Owner

dfsp-spirit commented Jun 7, 2022

Hm, interesting question. I wanted to try to render a brain to R shiny anyways, so I kind of have this on my internal to-do list.

I just started a new position though, so I currently can't do it at work. I'll have a look as soon as I find the time.

I can tell you through that because fsbrain uses the rgl renderer internally, the solution most likely will involve getting rgl to display stuff in a shiny window. I may have to do something in the fsbrain code to do that, but I'm not sure. I just found this but cannot test at work.

@dfsp-spirit dfsp-spirit self-assigned this Jun 7, 2022
@dipterix
Copy link
Author

dipterix commented Jun 7, 2022

Congratulations on the new position! I was talking with my PI about your great work yesterday.

Yes, basically rgl started to support WebGL rendering around 3 years ago so you can visualize 3D content with web browsers. However, it might be tricky to render mesh with massive vertices. This is because in xQuartz, you can use C to directly access data via shared memory, but depending on HtmlWidgets requires serializing the R object to JSON, which is a little slow. The way I handle this issue is to cache everything into JSON first. Loading the mesh is just fast in browsers (from 1min to 5sec).

Haven't actually tried rgl to render brain though, but I think it's worthwhile. (Maybe they have faster serialization, or people can just wait)

@dfsp-spirit dfsp-spirit added the investigate needs some investigation label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate needs some investigation
Projects
None yet
Development

No branches or pull requests

2 participants