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

Issue creating an observe shiny element within a newly loaded shiny module #682

Open
guigui351 opened this issue Jun 13, 2022 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@guigui351
Copy link

Hi to the SafetyGraphics team,

First of all I would like to thank you the work you've done. It's incredibly amazing !

I would need your help on the following issue. I am trying to include a new shiny module within SafetyGraphicsApp. It works well as you see below. However I don't figured out why when I include the following commented code in my shiny server the application breaks (the observe function doesn't work even without anything inside..). I followed exactly what has been done with the "mod_timeToAE.R" module you've created in the past.

image

tornadoExplorer_ui <- function(id) {
  ns <- NS(id)
  
  sidebar <- sidebarPanel(
    width = 3, 
    style = "font-family: monospace; position: fixed; width: 20%; top: 88px; height: 300px; overflow-y: auto;",
    selectizeInput(
      ns('groupvar'), 
      "AE Grouping:",   
      choices = NULL, 
      multiple = FALSE
    ),
  )
  
  main <- mainPanel(
    width = 9, 
    style = "position: fixed; left: 21%; top: 88px; height: 800px; overflow-y: auto;",
    plotOutput(ns("tornadoExplorer"))
  )
  
  ui<-fluidPage(
    sidebarLayout(
      sidebar,
      main,
      position = c("left"),
      fluid=TRUE
    )
  )
  return(ui)
}

tornadoExplorer_server <- function(input, output, session, params) {
  
  ns <- session$ns
  
  # observe({
  # 
  #   # Define choices for AE grouping
  #   updateSelectizeInput(
  #     session,
  #     'groupvar',
  #     choices = c(
  #       'None',
  #       rlang::sym(params()$settings$aes$severity_col),
  #       rlang::sym(params()$settings$aes$serious_col)
  #     ),
  #     selected = 'None'
  #   )
  # 
  # })
  
  settingsR <- reactive({
    settings <- params()$settings
    settings$group <- input$groupvar
    return(settings)
  })

  #draw the chart
  output$tornadoExplorer <- renderPlot({
    tornadoPlot_shiny(params()$data,
                      params()$settings,
                      input$groupvar)
  }, width = 1100, height = 800, res = 80)
}

I'm using the following pre-process code to run it:

image

Would you be able to help me on that issue?

Thanks.

@jwildfire jwildfire added the question Further information is requested label Jun 13, 2022
@jwildfire
Copy link
Contributor

Thanks for the note @guigui351. I've had issues with the timing of those update functions in the past. Will take a look and see if I can figure out what's going on.

@jwildfire
Copy link
Contributor

jwildfire commented Jun 13, 2022

Here's the image above converted to text:

meta_aes_custom<- read_csv("meta_aes.csv")[]

custom_meta <- bind_rows (safetyGraphics::meta %>% filter (domain != "aes"), meta_aes_custom)

#Chart Configuration
sdtm_dm <- safetyData:: sdtm_dm %>% 
   filter (ARMCD != "Scrnfail") %>%
   mutate (ARM if_else (ARM != "Placebo", "Treatment", "Placebo"))

sdtm <- list(
   dm=sdtm_dm,
   aes=safetyData::sdtm_ae,
   labs safetyData:: sdtm_lb
)

charts <- makeChartConfig()
charts$tornadoshiny<-prepareChart (read_yaml ('mod_tornadoPlot.yaml'))
#options (shiny.error = browser)
safetyGraphicsApp (domainData = sdtm, charts charts, meta=custom_meta)

@jwildfire
Copy link
Contributor

Hey @guigui351 - that observer seems to be working as expected for me (see test code below). If you're able to share your tornadoPlot code, I'd be happy to help debug further. Would also be happy to collaborate on a PR that adds it to safetyCharts as a new chart if that is of interest.

Here's the reprex with the working observer:

library(safetyGraphics)
library(tidyverse)

tornadoPlot_shiny <- function(data, settings, group){
    plot(-1:1, -1:1)
    text(0, 0, group)
}

tp<-list(
  env="safetyGraphics",
  name="Tornadoplot",
  label="Tornadoplot",
  type="module",
  domain=list("aes","dm"),
  workflow=list(
      server="tornadoExplorer_server",
      ui="tornadoExplorer_ui"
  )
)

tornadoExplorer_ui <- function(id) {
  ns <- NS(id)
  
  sidebar <- sidebarPanel(
    width = 3, 
    style = "font-family: monospace; position: fixed; width: 20%; top: 88px; height: 300px; overflow-y: auto;",
    selectizeInput(
      ns('groupvar'), 
      "AE Grouping:",   
      choices = NULL, 
      multiple = FALSE
    ),
  )
  
  main <- mainPanel(
    width = 9, 
    style = "position: fixed; left: 21%; top: 88px; height: 800px; overflow-y: auto;",
    plotOutput(ns("tornadoExplorer"))
  )
  
  ui<-fluidPage(
    sidebarLayout(
      sidebar,
      main,
      position = c("left"),
      fluid=TRUE
    )
  )
  return(ui)
}

tornadoExplorer_server <- function(input, output, session, params) {
  
  ns <- session$ns
  
  observe({
  
    # Define choices for AE grouping
    updateSelectizeInput(
      session,
      'groupvar',
      choices = c(
        'None',
        rlang::sym(params()$settings$aes$severity_col),
        rlang::sym(params()$settings$aes$serious_col)
      ),
      selected = 'None'
    )
  
  })
  
  settingsR <- reactive({
    settings <- params()$settings
    settings$group <- input$groupvar
    return(settings)
  })

  #draw the chart
  output$tornadoExplorer <- renderPlot({
    tornadoPlot_shiny(params()$data,
                      params()$settings,
                      input$groupvar)
  }, width = 1100, height = 800, res = 80)
}

#meta_aes_custom<- read_csv("meta_aes.csv")[]
#custom_meta <- bind_rows (safetyGraphics::meta %>% filter (domain != "aes"), meta_aes_custom)

#Chart Configuration
sdtm_dm <- safetyData:: sdtm_dm %>% filter (ARMCD != "Scrnfail") %>%
  mutate (ARM = if_else(ARM != "Placebo", "Treatment", "Placebo")) 

sdtm <- list(
  dm=sdtm_dm,
  aes=safetyData::sdtm_ae,
  labs=safetyData:: sdtm_lb
)

charts <- makeChartConfig()
charts$tornadoshiny<-prepareChart(tp)

#safetyGraphicsApp (domainData = sdtm, charts=charts, meta=custom_meta)
safetyGraphicsApp (domainData = sdtm, charts=charts)

@jwildfire jwildfire self-assigned this Jun 15, 2022
@guigui351
Copy link
Author

Hi Jeremy,

Thanks for looking at it. In the meantime I tried to create a standalone package (tornadoplot) and make it in a way that it could be integrated in the safetyGraphics app, unfortunately it failed at some point and I'm unable to find the reason. When you'll have some time you'll mind to have a quick look at it? I pushed the package to Github and updated the readme with the pre-process steps I'm making.

https://github.com/guigui351/tornadoplot

The package doesn't do much yet, my initial goal is have something that could run in a standalone way and that could be integrated in safetyGraphicsApp before going to more customization.

I would really appreciate your help to help me understand what I'm doing wrong to have this package loaded in your shiny app.

Please note that the yaml configuration file is located in "inst/config". As I'm using golem, I'm not sure how the different modules are read by the app, can it contains multiple ui/server modules in the "workflow"?

Thank you very much.

@jwildfire
Copy link
Contributor

That's great @guigui351 - I'll take a look soon and see if I can get it running in safetyGraphics!

@jwildfire
Copy link
Contributor

@guigui351 You might take a look at https://github.com/SafetyGraphics/volcanoPlot for reference. It's also a standalone Shiny application that is designed to be integrated with the safetyGraphics app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants