No output from Reactive Module using selectizeGroup with EventReactive

I am creating a dashboard that queries a db to produce a table. The query's filter contains a reactive variable in which its value is determined by the slider. However, I cannot put filters on the resulting reactive dataset since shinyWidgets does not take in reactiveValues as input. I looked t similar posts, however none of them has a solution for a reactive dataset produced WITH a DATE FILTER under observeEvent and then allowing filters on the resulting data results for the other 2 variables AFTER the query runs. The example I have won't show the actual query but a contrived one in the comment section. I provided a dataset to illustrate what I am trying to do

# Load Packages----
library(shiny)
library(data.table)
library(ggplot2)
library(DBI)
library(odbc)
library(shinyWidgets)

# Global Options----
options(DT.options = list(pageLength = 25,searching = FALSE))
values <- reactiveValues(df_data = 
                      NULL)


# Initialize Variables
data_summary = data.table(Device_Status = c("Healthy_Devices","Unhealthy_Devices"),Total = c(0,0))

# Establish Snowflake Connection----
con1 <- dbConnect(odbc::odbc(), 
                  .connection_string = "Driver=/opt/snowflake/snowflakeodbc/lib/universal/libSnowflake.dylib; 
                              Server=spireon.snowflakecomputing.com; 
                              authenticator = externalbrowser;
                              UID = sdaner@spireon.com;
                              Database = SPIREONDWBI_DEV;
                              role = DEV_SQL_DEV")
# UI----
ui <- fluidPage(
    
  
    sidebarPanel(
     
        # Slider
        sliderInput(inputId = "num", 
                    label = "Number of Previous Days from Today", 
                    value = 1, min = 1, max = 365),
        # Action Button
        actionButton(inputId = "click", label = "click to refresh"),
        # Space
        hr(),
        # Filters
            selectizeGroupUI(
                id = "my-filters",
                label = h3("Filters:"),
                inline = FALSE,
                params = list(
                    var_one = list(inputId = "var_one", title = "Select Account", placeholder = 'select'),
                    var_two = list(inputId = "var_two", title = "Select Device Type", placeholder = 'select')
                            )
                         )
               
            ),
    
    mainPanel(
        DT :: dataTableOutput("table"),
        plotOutput("barChart"))
)

# Server----
server <- function(input, output) {
  
 
  
observeEvent(input$click, {
    
    #Initialize Date
    past_date = Sys.Date() - input$num
    
    # Create Query
    query = paste("SELECT 
                      c.calendar_date,
                      c.device,
                      IFNULL(d.dailyautoloc,0) dailyautoloc,
                      d.account,
                      d.device_type
                      FROM SPIREONDWBI_DEV.DANER_TEST.CALENDAR_DEVICE_V2 c
                      LEFT JOIN SPIREONDWBI_DEV.DANER_TEST.DEVICEHEALTH d
                      ON c.calendar_date = d.date
                      AND c.device = d.device
                      WHERE c.calendar_date =","'",past_date,"'","
                      ORDER BY dailyautoloc DESC")
    
    values$df_data = as.data.frame(DBI::dbGetQuery(con1, query))
  

     
    })
  

  

# 
#   observe({
#   if(!is.null(values$df_data)){
# 
# 
#       res_mod = callModule(
#         module = shinyWidgets::pickerGroupServer,
#         id = "my-filters",
#         data = values$df_data,
#         vars = c("var_one","var_two")
#       )
# 
#   }
#    })





  

  
  # Render Data Table
  output$table <- DT :: renderDataTable({
   values$df_data
    #res_mod()
  })
  
  # #  Calculate Healthy and Unhealthy Devices----
  # dt = reactive(as.data.table(data()))
  # summary = reactive(data_summary[,Total := c(dt()[DAILYAUTOLOC >=1,.N],dt()[,.N] - dt()[DAILYAUTOLOC >=1,.N])])
  # #observe(print(data()[[1,1]]))
  # 
  # output$barChart = renderPlot({
  #   
  #   ggplot(summary(),aes_string(x = names(summary())[1], y = names(summary())[2], fill = names(summary())[1])) +
  #     geom_bar(stat = "identity", position=position_dodge())+ 
  #     geom_label(aes(label = formatC(summary()[,Total],format = "d",big.mark=","))) +
  #     ggtitle(paste("Device Health Status For",data()[[1,1]],sep =" ")) +
  #     theme(axis.ticks = element_blank(),
  #           panel.background = element_blank(),
  #           axis.title.x = element_blank(),
  #           axis.title.y = element_blank(),
  #           plot.title = element_text(face = "bold",hjust = 0.4),
  #           axis.text.x = element_text(color = "black",size = 10),
  #           legend.position = 'none')
  #   
  # })
}

# Run the application----
shinyApp(ui = ui, server = server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.