UI not updating the charts

For some reason, after plotting the charts once, the UI function in the app is not updating the charts. The server function organizes the data but the UI function is not plotting them.

The code looks as follows.

getData <- dbGetQuery(con, sql_str)

plotting_module_UI <- function(id) {
  message("I am in module_UI. Am I expected to be here?")
  ns <- NS(id)
                         selectInput(ns("s_groups"), "Group", c("Group1", "Group2", "Group3", "Group4", "Group5"), selected = NULL, multiple = FALSE, selectize = TRUE, width = 1000, size = NULL)
                selectInput(inputId = ns("s_xaxis"), label = "X - Axis", choices = c("Option1", "Option2", "Option3", "Option4", "Option4"), selected = "Option1", multiple = FALSE, selectize = TRUE, width = NULL, size = NULL)
         plotlyOutput(ns("s"), height = "800px", width = "1500px")
  message("I am in module_UI. If seeing this message, it means that you must be seeeing the charts.")

plotting_module <- function(input, output, session, cn){
  message("I am in module. Am I expected to be here?")
  newdata <- subset(getData, getData$parameter==cn)
  output$s <- renderPlotly(
    plot_ly(newdata, x = eval(parse(text = paste("newdata$",input$s_xaxis,sep = ""))), y = newdata$fValue, height = 768, width = 1320, type = "box", 
            color = eval(parse(text = paste("newdata$",input$s_groups,sep = ""))), pointpos = 0, boxpoints = 'all') %>% 
      layout(yaxis = list(title = unique(newdata$parameter), range = c(min(min(unique(newdata$fValue)),unique(newdata$fLowerSpec)), max(max(unique(newdata$fValue)),unique(newdata$fUpperSpec))), showline = TRUE, zeroline = TRUE), margin = list(l = 100)) %>% layout(boxmode = "group") %>% 
      layout(xaxis = list(title = input$s_xaxis, showline = TRUE, zeroline = TRUE, tickangle = 90, mirror = "ticks")) %>%
      layout(legend = list(x = 100, y = 1.25, orientation = "h", size = 25)) %>% 
      layout(shapes = list(hline(unique(newdata$fLowerSpec)),hline(unique(newdata$fUpperSpec))))
  message("I am in module. if seeing this message, it means that plotly has plotted the charts")

ui <- fluidPage(
  selectInput("select1", label = h3("Select 1"),
              choices = list("Option1", "Option2", "Option3"),
              selected = NULL),
  textInput("select2", label = h3("Select2")),
  textInput("select3", label = h3("Select3"), value = "13315"),
  dateInput("end_date", label = h3("Enter end date (default is today)"), value = NULL),
  numericInput("num_days", label = h3("Enter the number of days for trend"), value = 30),
  actionButton("start", "Submit (draw plots)"),
    lapply(1:5, function(i) plotting_module_UI(unique(getData$parameter)[i]))

server <- function(input, output, session) {
  output$table <- renderTable(getData)
               {   req(input$start)
                 message("I am back to observe event right now. Heading to new now")
                 getData <<- dbGetQuery(con, sql_str)
                 message("Got the data from the database. Starting to plot the charts now....")
                 output$txt_output <- renderText({ length(unique(getData$))})
                 lapply(1:length(unique(getData$parameter)), function(i) callModule(plotting_module, unique(getData$parameter)[i], unique(getData$parameter)[i]))
                 message("I am back to observe event right now. You should have the plots by now?") 
  message("I am outside the observe event and should definitely plot now.")
  # lapply(1:length(unique(Sc$Report)), function (i) callModule(plotting_module, unique(Sc$Report)[i], unique(Sc$Report)[i]))   #--------paste("outer",i, sep = "")

The server function is fetching the data from the database and organizing the data fro plotting. However, the ui function just does not plot it. Actually, it is not even being called! (I can say this based on the different message() commands i have placed in the code).

Also note that fetching the data from the data base is done two. Once is in the beginning of the code and the second time is being done in the server function.I had to do it twice because R would give me an error as "getData" not found. Number of parameters foound in getData determine how many charts are being plotted.

To make things simple and quick, the first time i try to get data from the database, I mention some dummy inputs so that no data is fetched (this was the only turn around solution that I could find). If there is some solution for this issue, it is highly appreciated.

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