Use showNotification() to monitor the dimensions of a reactive variable

131 views
Skip to first unread message

Sviatoslav Kendall

unread,
Sep 6, 2017, 5:52:33 PM9/6/17
to Shiny - Web Framework for R
I'm developing an app that allows users to explore a complex dataset through several different types of analysis. The app is composed of several modules; one module allows users to subset the dataset and returns a reactive data frame which is used as input for the other modules which handle different types of analyses. I'd like to provide the user with a persistent visual cue that they are working with a subset of the full dataset whenever that happens to be the case. 

The showNotification() function looks like the right tool for this job but I'm not sure how best to implement it. Here's my server code:

shinyServer(function(input, output) {

# Create reactive dataframe to track patient selection
 
Filtered_Data = callModule(Selection_Module, "GLOBAL", DEMO_LIST, my_data)
 
 
# Show notification if filters have been applied and there are fewer than 73 patients in Filtered_Data
 
# n_filt = reactive({
 
#   n = Filtered_Data()
 
#   return(nrow(n))
 
#  })
 
#  observeEvent(n_filt() < 73,{
 
#    showNotification(paste("Working with", n_filt(), "patients..."), duration = NULL)
 
#  })

# Feed reactive data frame into other tabs as function call
  callModule
(Genomics_Outcome, "OUTCOME", Filtered_Data)

  callModule
(CrossTab, "CROSS", Filtered_Data)

  callModule
(Clonality, "CLONE", Filtered_Data)

})


The code which I've commented out does not work - it causes the whole app to crash with an error message that suggest there's something wrong with the command,
n=Filtered_Data()
...but I can't tell if its something simple like a syntax error or something more complicated like the nature of reactive values. 



Yoav Magor

unread,
Sep 7, 2017, 5:36:15 AM9/7/17
to Shiny - Web Framework for R
I use something similar:

# add this code inside the server function
rv <- reactiveValues()
observeEvent(rv$message, {
    if(is.null(rv$message)) {return()}
    showModal(modalDialog(title = "NOTIFICATION", rv$message, easyClose = TRUE, footer = NULL))
    rv$message <- NULL
  })

i'd consider keeping an additional reactive value (rv$nrow), which will be updated at the end of Filtered_Data().
this way (there are numerous other alternatives i'm sure) you can easily call for such a notification from anywhere in your code:

rv$message <- paste(paste("Working with", rv$nrow, "patients...")) 
Reply all
Reply to author
Forward
0 new messages