Home > OS >  R Shiny - how to simplify the following code?
R Shiny - how to simplify the following code?

Time:01-23

I would like to know how I can simplify the following code?

  observeEvent(input$structure_explorer_refresh, {
    shinyjs::reset("structure_explorer_form")
  })
  observeEvent(input$property_refresh, {
    shinyjs::reset("property_form")
  })
  observeEvent(input$structure_activity_refresh, {
    shinyjs::reset("structure_activity_form")
  })  
  observeEvent(input$structure_target_refresh, {
    shinyjs::reset("structure_target_form")
  })    
  observeEvent(input$target_id_refresh, {
    shinyjs::reset("target_id_form")
  }) 
  observeEvent(input$target_activity_refresh, {
    shinyjs::reset("target_activity_form")
  })  
  observeEvent(input$drug_target_refresh, {
    shinyjs::reset("drug_target_form")
  })    
  observeEvent(input$drug_info_refresh, {
    shinyjs::reset("drug_info_form")
  })  
  observeEvent(input$assay_id_refresh, {
    shinyjs::reset("assay_id_form")
  })  

I have tried to apply this enter image description here

CodePudding user response:

Maybe like this:

xxx <- c(
  "structure_explorer_",
  "property_",
  ......
)

for(x in xxx) {
  observeEvent(input[[paste0(x, "refresh")]], {
    shinyjs::reset(paste0(x, "form"))
  })
}
  • Related