0

Sorry for the lack of a reproducible example, but the actual data I am working with is too specific to be shared here. I can share the data upon request, though.

My ui.R script is this:

    suppressPackageStartupMessages({
  library(shiny)
  library(shinyjs)
  library(data.table)
  library(leaflet)
  library(sf)
  library(tidyverse)
  library(RColorBrewer)
  library(plotly)
  library(ggmap)
  library(ggspatial)
  library(htmltools)
  library(crosstalk)
  library(tidyverse)
  library(leaflet.extras)
  library(geofacet)
})

shinyUI(fluidPage(
  titlePanel("Mosquito and environmental data Visualization"),
  # javascript code to enable/disable buttons
    tabsetPanel(
      tabPanel("About this App", htmlOutput("About this app")),
      tabPanel("Trapping data", fluid = TRUE,
               sidebarLayout(sidebarPanel(width = 2,
                                          selectInput("region", label = "Select Region", choices = c("Coachella Valley", "Suffolk County")),
                                          selectizeInput("year_vec", label = "Years", choices = 2001:2021, multi = TRUE),
                                          selectInput("weekfrom", label = "begin week", choices = 1:53),
                                          selectInput("weekto", label = "end week", choices = 1:53, selected = 53),
                                          selectInput("spat_var",label = "Spatial scale",choices = c("County/MVCAD","NLDAS","ECOSTRESS")),
                                          selectInput("summary_fun",label = "Parameter",choices = c("MIR","MLE","Mosq. unstd","Mosq. std","Wk. first pos.")),
                                          actionButton('go', label = 'Plot')),
                             mainPanel(plotOutput('trap_map', height = '900px', width= '1200px')))), 
      tabPanel("Environmental data", fluid = TRUE,
               sidebarLayout(sidebarPanel(width = 2, 
                                          selectInput("region", label = "Select Region", choices = c("Coachella Valley", "Suffolk County")),
                                          selectizeInput("year_vec", label = "Years", choices = 2001:2021, multi = TRUE),
                                          selectInput("weekfrom", label = "begin week", choices = 1:53),
                                          selectInput("weekend", label = "end week", choices = 1:53, selected = 53),
                                          selectInput("spat_var",label = "Spatial scale",choices = c("County/MVCAD","NLDAS","ECOSTRESS")),
                                          selectInput("env_var",label = "Env. Variable",choices = c("TMP","EVP")), 
                                          actionButton('go', label = 'Plot')), 
                             mainPanel(plotOutput('env_map', height = "900px", width = "1200px")))),
      tabPanel("Forecasts", mainPanel(plotOutput('forecast maps', height = "600px", width = "1000px")))
    )
))

and my server.R script is this:

suppressPackageStartupMessages({
  library(shiny)
  library(shinyjs)
  library(data.table)
  library(leaflet)
  library(leaflet.extras)
  library(leafsync)
  library(sf)
  library(tidyverse)
  library(RColorBrewer)
  library(plotly)
  library(ggmap)
  library(ggspatial)
  library(htmltools)
  library(htmlwidgets)
  library(crosstalk)
  library(lubridate)
  library(geofacet)
  library(yaml)
})

 {
#   ## Read Input yaml file ----
   input_args = yaml.load_file("test.yaml"); #Set path to location with the required YAML file
#   ## Get required source files ----
   source(input_args$data_script); 
   source(input_args$plot_fn_script); 
   source(input_args$mle_fns); 
 }

###################################

shinyServer(function(input, output, session) {
  
  # Produce maps for mosquito trapping data
  
    
  output$trap_map <- renderText({
    
    isolate({
      year_vec <- input$year_vec
      weekfrom <- input$weekfrom
      weekto <- input$weekto
      spat_var <- input$spat_var
      region <- input$region
      summary_fun <- input$summary_fun
      #env_var <- input$env_var
    
      if (input$go == 0)
        return()
      # sprintf("The selected input variables are %s for region %s at the %s spatial scale, from week %s to week %s, for the years %s",
      #         summary_fun, region, spat_var, weekfrom, weekto, year_vec)
       trap_map(region = region, year_vec = year_vec, weekfrom = weekfrom, weekto = weekto, spat_var = spat_var, summary_fun = summary_fun)
    })})
  
  # Produce maps for environmental data
  output$env_map <- renderText({
    
   isolate({

      year_vec <- input$year_vec
      weekfrom <- input$weekfrom
      weekto <- input$weekto
      spat_var <- input$spat_var
      region <- input$region
      env_var <- input$env_var
      
      if (input$go == 0)
        return()
      # sprintf("The selected env. variables are %s for region %s at the %s spatial scale, from week %s to week %s, for the years %s",
      #         env_var, region, spat_var, weekfrom, weekto, year_vec)
      env_map(region = region, year_vec = year_vec,weekfrom = weekfrom, weekto = weekto, env_var = env_var)
    }) })
  
    
})

My problem is, I am unable to see any of my plots in the app, upon running the app. The functions I have in the plot_maps.R script produce the maps exactly as I want them when I run them independent of the app, but there is no output at all when I run them in the app. Where am I going wrong?

I'd appreciate any pointers in the code so far, and can also share the other functions and code if that helps.

Thanks a lot!

KVemuri
  • 194
  • 1
  • 16
  • I don’t see any `renderPlot`s in your server function… And everything that *is* inside any `renderXXX` is wrapped in an `isolate` so i don’t think I’d expect to see anything in the app. – Limey Jul 22 '22 at 19:23
  • @Limey Thanks, the `renderText` was a holdover from when I tested to see if any output was possible from the function, but I since changed that to `renderPlot`. But the braces around `isolate` were a great suggestion, that helped solve (one part of) the problem! – KVemuri Jul 22 '22 at 20:05

0 Answers0