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

m_grid does not update in Shiny app with selectInput #42

Closed
alanzos opened this issue Sep 16, 2021 · 3 comments
Closed

m_grid does not update in Shiny app with selectInput #42

alanzos opened this issue Sep 16, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@alanzos
Copy link

alanzos commented Sep 16, 2021

Hi,

Thanks for making r3dmol. It's a really nice package and easy to use.

I'm using m_grid in a Shiny app with selectInput. But the output graphic is not updated when changing the input in the selection menu on the left.

The individual graphics are updated, but not the multi graphic.

And I get this error on the console:
Warning in renderWidget(instance) :
Ignoring explicitly provided widget ID "c6ce055b66d1daf14e50"; Shiny doesn't use them

Any idea why? and a possible solution?

Thanks in advance :)

Example below:

library(shiny)
library(r3dmol)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("selected_id", "Choose a PDB ID:", choices=c("3G5X","7A2A","5IJ5")),
    ),
    mainPanel(
      ## Choose multi or individual, but not both at the same time
      r3dmolOutput(outputId = "structure_multi"),
      # r3dmolOutput(outputId = "structure_individual"),
      )
    )
  )
  
server <- function(input, output, session) {
  
  output$structure_individual <- renderR3dmol({
    r3dmol() %>%
      m_add_model(data = m_fetch_pdb(input$selected_id)) %>%
      m_zoom_to() %>%
      m_set_style(style = m_style_cartoon(color = "spectrum"))
    
  })
  
  output$structure_multi <- renderR3dmol({
    m1 <- r3dmol() %>%
      m_add_model(data = m_fetch_pdb(input$selected_id)) %>%
      m_zoom_to()
    
    m2 <- m1 %>%
      m_set_style(style = m_style_cartoon(color = "spectrum"))
    
    m3 <- m1 %>%
      m_set_style(style = m_style_stick())
    
    m4 <- m1 %>%
      m_set_style(style = m_style_sphere())
    m_grid(
      viewer = list(m1, m2, m3, m4),
      control_all = TRUE,
      viewer_config = m_viewer_spec(
        backgroundColor = "black"
      )
    )
    })
}


shinyApp(ui, server)
@swsoyee swsoyee self-assigned this Sep 16, 2021
@swsoyee swsoyee added the bug Something isn't working label Sep 16, 2021
@swsoyee
Copy link
Owner

swsoyee commented Sep 16, 2021

Thanks for reporting that. Although I have not done enough research, but I think this should be a bug, thank you very much for the sample, I will go to solve the problem as soon as possible.

swsoyee added a commit that referenced this issue Sep 16, 2021
fix: grid layout dose not update in Shiny app (#42)
@swsoyee
Copy link
Owner

swsoyee commented Sep 16, 2021

@alanzos I think I have fixed the bug, please use the latest version and have a try. see #44.

# install.packages("devtools")
devtools::install_github("swsoyee/r3dmol")

About the waring in the console

And I get this error on the console:
Warning in renderWidget(instance) :
Ignoring explicitly provided widget ID "c6ce055b66d1daf14e50"; Shiny doesn't use them

You could use grid$elementId <- NULL to ignore them. see plotly/plotly.R#985.

library(shiny)
library(r3dmol)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("selected_id", "Choose a PDB ID:", choices=c("3G5X","7A2A","5IJ5")),
    ),
    mainPanel(
      ## Choose multi or individual, but not both at the same time
      r3dmolOutput(outputId = "structure_multi"),
      r3dmolOutput(outputId = "structure_individual"),
    )
  )
)

server <- function(input, output, session) {
  
  output$structure_individual <- renderR3dmol({
    r3dmol() %>%
      m_add_model(data = m_fetch_pdb(input$selected_id)) %>%
      m_zoom_to() %>%
      m_set_style(style = m_style_cartoon(color = "spectrum"))
  })
  
  output$structure_multi <- renderR3dmol({
    m1 <- r3dmol() %>%
      m_add_model(data = m_fetch_pdb(input$selected_id)) %>%
      m_zoom_to()
    
    m2 <- m1 %>%
      m_set_style(style = m_style_cartoon(color = "spectrum"))
    
    m3 <- m1 %>%
      m_set_style(style = m_style_stick())
    
    m4 <- m1 %>%
      m_set_style(style = m_style_sphere())
    
    grid <- m_grid(
      viewer = list(m1, m2, m3, m4),
      control_all = TRUE,
      viewer_config = m_viewer_spec(
        backgroundColor = "black"
      )
    )
    grid$elementId <- NULL # suppress the `Shiny doesn't use them` warning
    grid
  })
}

shinyApp(ui, server)

If you still have any problem please let me know. Thank you!

@alanzos
Copy link
Author

alanzos commented Sep 16, 2021

Wow that was fast, it works perfectly. Many thanks 👍

@alanzos alanzos closed this as completed Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants