Shiny Dashboards not populating data

I/ve been trying to publish my first shinydashboard, however Ive come across an issue where the dashboard wont load, the ui interface loads but none of the plots / maps are populated, and the RStudio console says its listening but produces no error report and doesn't complete the load.

I have managed to publish to Shiny.apps and the same is there. [https://s3875011.shinyapps.io/ass2-app/?_ga=2.112724740.1408124919.1606795436-1782373697.1606289306]

I had it working right before i installed the latest version of rsconnect which requested an update just before i tried to publish to Shiny, and since there it hasnt produced anything. I have checked all the plots run independently to the shinydashboard, and that the data loads correct. I have also updated all packages within RStudio and updated R itself, and still no help.

I have included by code below.



# Load packages and prepare data

library(readr)
library(dplyr)
library(ggplot2)
library(plotly)
library(scales)
library(htmltools)
library(htmlwidgets)
library(formattable)
library(maptools)
library(leaflet)
library(shiny)
library(shinydashboard)

#load data 

taxdata <- read_csv("taxdata.csv") %>%
  mutate(avg_gift = (giftsordonations_dollars / giftsordonationsno))

## format state data

taxdata_gryear <- taxdata %>%
  group_by(taxyear, state_territory) %>%
  summarise(total_gift_dollars = sum(giftsordonations_dollars),
            total_gift_numbers = sum(giftsordonationsno),
            total_individuals = sum(numberofindividualsno),
            total_salary = sum(salaryorwages_dollars),
            total_income = sum(taxableincomeorloss_dollars)) %>%
  mutate(average_gift = total_gift_dollars/total_gift_numbers,
         percent_ofindividualsgiving = total_gift_numbers/total_individuals,
         percent_ofsalary = total_gift_dollars/total_salary,
         percent_ofincome = total_gift_dollars/total_income,
         average_salary = total_salary/total_individuals,
         average_income = total_income/total_individuals)

#load demographics

taxdata_grpc_j <- read_csv("taxdata_grpc_j.csv")

glimpse(aus_pc.shp)
# read shape file

aus_pc.shp <- readShapeSpatial("POA_2016_AUST.shp", delete_null_obj=TRUE)

summary(aus_pc.shp)
# merge shape file

merge.aus_pc.shp <-sp::merge(aus_pc.shp, taxdata_grpc_j,
                             by="POA_NAME16", duplicateGeoms = TRUE)

#### Formats for map

#create bins
bins <- quantile(
  merge.aus_pc.shp$total_gift_dollars201718,
  probs = seq(0,1,.2), names = FALSE, na.rm = TRUE)
bins


#apply colour

pal <- colorBin(  "Purples", domain = merge.aus_pc.shp$total_gift_dollars201718, bins = bins, pretty = FALSE)

#apply labels

labels <- sprintf(
  "<strong>Postcode: </strong> %s <br/> 
    <strong>Median Age: </strong> %s
   <strong>Amount Given: </strong> %s <br/>
  <strong>Median Wkly Household Income: </strong> %s",
  merge.aus_pc.shp$POA_NAME16,
  merge.aus_pc.shp$Median_age_persons,
  currency(merge.aus_pc.shp$total_gift_dollars201718, digits = 0L),
  currency(merge.aus_pc.shp$Median_tot_hhd_inc_weekly, digits = 0L)) %>% 
  lapply(htmltools::HTML)



###########################################################################
# Assign ui function


ui <- dashboardPage(skin = "purple",
  
      dashboardHeader(),
  
      dashboardSidebar(width = 125,
          sidebarMenu(
                menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
                menuItem("PostCode", icon = icon("th"), tabName = "PostCode"),
                menuItem("References", icon = icon("th"), tabName = "References"))
                            ),
  
      dashboardBody(
           tabItems(
      # First tab content    
             tabItem(tabName = "dashboard",
                    fluidRow(
                          box(h4("% of Individuals Giving"), plotlyOutput("p3"), width = 4, height = 350),
                          box(h4("Average Giving per Individual"), plotlyOutput("p12"), width = 4, height = 350),
                          box(h4("Total Amount Gifts Claimed"),plotlyOutput("p11"), width = 4, height = 350)
                    ),
                     
                    fluidRow(
                      box(h4("% of Individuals Giving"), plotlyOutput("p3"), width = 4, height = 350),
                      box(width = 4),
                      box(width = 4)
                      
                    )
                    ),
                
       # Second tab details content
              tabItem(tabName = "PostCode",
                    fluidRow(
                          box(h4("Gifts Given"), leafletOutput("map"), width = 7),                          
                          box(h4("Average Amount Given and Number of Gifts"), plotlyOutput("p10"), width = 5)
                      ),
                    fluidRow(
                      box(width = 12)
                      )
                      ),
      
       # third tab content
              tabItem(tabName = "References", h2("References")
                    ))
      )      
)
    

      
  








#############################################################################
# Assign server function

server <- function(input, output, session) {
  
  
  output$p3 <- renderPlotly({
    
    p3 <- ggplot(taxdata_gryear, aes(x = taxyear, 
                                     y = percent_ofindividualsgiving, 
                                     group = state_territory, 
                                     colour = state_territory), size=3) +
      geom_line() +
      geom_point(aes( text = paste('Financial Year:', taxyear,
                                   '<br>State/Territory:', state_territory,
                                   '<br>% of Individuals Giving:', percent (percent_ofindividualsgiving)))) +                              
      scale_colour_brewer(palette="PuOr", name = "State") +
      theme_minimal() +
      xlab("Financial Year") +
      scale_y_continuous(name="% of Individuals Giving", labels = scales::percent) +
      theme(axis.text.x = element_text(angle = 45, hjust = 1)) 
    
      ggplotly(p3, tooltip = "text", height = 350, width = 400 )
    
  })
  


output$p12 <- renderPlotly({
  
p12 <- ggplot(taxdata_gryear, 
                aes(x = taxyear, y = average_gift )) + 
    geom_boxplot(lwd=0.2) + 
    geom_point(size = 2, aes(colour = state_territory, 
                            text = paste('Financial Year: ', taxyear,
                                         '<br>State/Territory:', state_territory,
                                         '<br>Average Gift:', currency(average_gift)))) +
    scale_colour_brewer(palette="PuOr", name = "State")  +
    theme_minimal() +
    labs(x = "Financial Year", y="Average Gift")  +
    scale_y_continuous(labels = scales::dollar_format()) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1)) 
  
    ggplotly(p12, tooltip = "text", height = 350, width = 400 )
  
} )



output$p11 <- renderPlotly({
  
p11 <- ggplot(taxdata_gryear, aes(x = taxyear, y=total_gift_dollars,  fill = state_territory)) +
    geom_col(aes (text = paste('Financial Year: ', taxyear,
                               '<br>State/Territory:', state_territory,
                               '<br>Total $$ Given:', currency(total_gift_dollars, digits = 0L)))) +
    scale_fill_brewer(palette="PuOr", name = "State") +
    theme_minimal() +
    labs (x = "Financial Year", y = "Total Gifts ($$)")  +
    scale_y_continuous(labels = scales::dollar_format(suffix = "b", scale = 0.000000001)) +
    theme(axis.text.x = element_text(angle = 45, hjust = 1))
  
    ggplotly(p11, tooltip = "text", height = 350, width = 400 ) 
  
} )



output$p7 <- renderPlotly({
  
p7 <- ggplot(taxdata_gryear, 
             aes(x=taxyear, y=average_salary, group=state_territory, colour = state_territory),size=3) +
  geom_line() +
  geom_point(aes( text = paste('Financial Year: ', taxyear,
                               '<br>State/Territory:', state_territory,
                               '<br>Average Salary:', currency(average_salary)))) +
  scale_colour_brewer(palette="PuOr", name = "State ") +
  theme_minimal() +
  labs(x = "Financial Year", y="Average Salary") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_y_continuous(labels=scales::dollar_format(suffix = "k", scale = 0.001))

  ggplotly(p7, tooltip = "text", height = 350, width = 400) 

} )



output$p10 <- renderPlotly({
  
p10 <- ggplot(taxdata_grpc_j, 
                aes(x = log(average_gift201718), y = log(total_gift_numbers201718) , colour = state_territory)) + 
    geom_point(aes (text = paste('Financial Year: ', taxyear201718,
                                 '<br>State/Territory:', state_territory,
                                 '<br>Postcode:', POA_NAME16,
                                 '<br>Number of Gifts:', format(as.integer(total_gift_numbers201718), big.mark=","),
                                 '<br>Average Gift:', currency(average_gift201718)))) +
    scale_colour_brewer(palette="PuOr", name = "State ")  +
    theme_minimal() +
    labs(x = "log(Average Gift)", y="log(Gifts)") 
  
    ggplotly(p10, tooltip = "text", height = 400, width = 400 )
  
})




output$map <- renderLeaflet({
  
  leaflet(merge.aus_pc.shp) %>%
    setView(lng = 131.036, lat = -25.344, zoom = 4)  %>%
    #fill colour  
    addPolygons(
      fillColor = ~pal(total_gift_dollars201718),
      weight = 1,
      opacity = 1,
      color = "white",
      dashArray = "3",
      fillOpacity = 0.7,
      highlight = highlightOptions(
        weight = 2,
        color = "#FFFF00",
        dashArray = "",
        fillOpacity = 0.7,
        bringToFront = TRUE),
      label = labels,
      labelOptions = labelOptions(
        style = list("font-weight" = "normal", padding = "3px 8px"),
        textsize = "14px",
        direction = "auto")) %>%
    addLegend(pal = pal, 
              values = ~total_gift_dollars201718, 
              opacity = 0.5, title = "Amount Given",
              labFormat = labelFormat(prefix = "$", digits=0),
              position = "bottomleft") %>%
    addTiles() %>%
    addEasyButton(easyButton(
      icon="fa-globe", title="Zoom to Level 4",
      onClick=JS("function(btn, map){ map.setZoom(4); }"))) 
  
})





}


#####################################################################################
# Deploy app


shinyApp(ui = ui, server = server)

You will likely get a faster response if you format your code so that it is easy to reproduce. You might instead consider linking to a working example in a github repository or gist.

OK thanks I will give that a go, however i actually have everything working earlier this week with a more messy code, and this is the simplified version so not sure this is the issue? thanks

plotlyOutput("p3") appears twice, however input and output ids are required to be unique. I've experienced silent errors caused by such in the past.

Thank you so much! I checked everything else except the outputs, you saved me a lot of time rewriting this from scratch tonight!!!!!!

This topic was automatically closed 7 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.