Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with publication of a Shiny App with R #387

Open
Alobondo opened this issue Jul 26, 2022 · 0 comments
Open

Error with publication of a Shiny App with R #387

Alobondo opened this issue Jul 26, 2022 · 0 comments

Comments

@Alobondo
Copy link

Hi all!! I have created a shiny dashboard and I wanted to publish it like a shinyapps.io, but when a do "Publish to Server" in RStudio a web page open up with a red message like "Error: An error has occurred. Check your logs or contact the app author for clarification." Despite this, I do not found any error message on Render or Terminal in RStudio. Could anyone help me with this issue? Another problem, is that my dashboard has 2 input lists, in order to change properties of the plots, these plots efectively change, but just with the firts 2 o 3 actions in both lists ¿how can I be sure that the dashboard will operate independetly of the number of options a user want to review?

Thank you community!!

---
title: "INDEX_2"
author: "Autor: XXX"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
# load data in 'global' chunk so it can be shared by all users of the dashboard

library(readr)

modelos <- read_csv("https://raw.githubusercontent.com/Alobondo/CC_ES_Example/main/ES_Modelos_GCM.csv")
T_cc <- read_csv("https://raw.githubusercontent.com/Alobondo/CC_ES_Example/main/ES_T_escaladas.csv")
PP_cc <- read_csv("https://raw.githubusercontent.com/Alobondo/CC_ES_Example/main/ES_PP_escaladas.csv")

date <- seq(as.Date("1990/1/1"), by = "month", length.out = dim(T_cc)[1])

modelos_vect <- as.data.frame(paste(modelos$Model, modelos$Ensemble, sep="_"))
colnames(modelos_vect)[1] <- "Model"

library(tidyverse)
library(reshape2)
PP_cc_yr <- PP_cc %>%
  select(-Mes, -Observado) %>% 
  melt(id.vars = c("Año")) %>%
  group_by(variable, Año) %>% 
  summarize(PP_perYEar = sum(value))
PP_cc_yr <- dcast(PP_cc_yr, Año ~ variable)

PP_obs_yr <- PP_cc %>%
  select(Año, Observado) %>% 
  melt(id.vars = c("Año")) %>%
  group_by(Año) %>% 
  summarize(PP_perYEar = sum(value))# %>% 
  #filter(!is.na(PP_perYEar))
  
T_cc_yr <- T_cc %>%
  select(-Mes, -Observado) %>% 
  melt(id.vars = c("Año")) %>%
  group_by(variable, Año) %>% 
  summarize(T_perYEar = mean(value))
T_cc_yr <- dcast(T_cc_yr, Año ~ variable)

T_obs_yr <- T_cc %>%
  select(Año, Observado) %>% 
  melt(id.vars = c("Año")) %>%
  group_by(Año) %>% 
  summarize(T_perYEar = mean(value))# %>% 
  #filter(!is.na(T_perYEar))

Inputs {.sidebar}

 selectInput("Model", label = h3("Modelo y Emsamble GCM"), 
    choices = as.list(modelos_vect$Model), 
    selected = modelos_vect$Model[1])

  selectInput("Resolution", label = h3("Escala temporal"), 
    choices = list("Mensual" = 1, "Anual" = 2), 
    selected = 1)

Series escaladas de precipitación y temperatura provenientes de los modelos GCM del CMIP6 para el escenario SSP5-8.5.

Row

Boxplot Temperatura

  num <- reactive(which(modelos_vect$Model == input$Model))

  uiOutput("dynamic")

  output$dynamic <- renderUI({
    if (as.integer(input$Resolution) == 1) plotOutput("plot1")
    else plotOutput("plot2")
  })

  output$plot1 <- renderPlot({
      selectedData_T <- reactive({T_cc[, num()+3]})

      boxplot(selectedData_T(),
      col="green",
      ylab=paste0("Modelo ", input$Model), xlab="Temperatura mensual [°C]",
      horizontal=TRUE)
  })

  output$plot2 <- renderPlot({
      selectedData_T <- reactive({T_cc_yr[, num()+1]})
      C <- data.frame(T_obs_yr[,2],selectedData_T())
      colnames(C) <- c("Obs", "Modelo")

      boxplot(C, col=c("red","green"), xlab="Temperatura anual [°C]",
      horizontal=TRUE)
  })

Boxplot Precipitación

  num <- reactive(which(modelos_vect$Model == input$Model))

  uiOutput("dynamic2")

  output$dynamic2 <- renderUI({
    if (as.integer(input$Resolution) == 1) plotOutput("plot3")
    else plotOutput("plot4")
  })

  output$plot3 <- renderPlot({
      selectedData_PP <- reactive({PP_cc[, num()+3]})

      boxplot(selectedData_PP(),
      col="cyan",
      ylab=paste0("Modelo ", input$Model), xlab="Precipitación mensual [mm]",
      horizontal=TRUE)
  })

  output$plot4 <- renderPlot({
      selectedData_PP <- reactive({PP_cc_yr[, num()+1]})
      C <- data.frame(PP_obs_yr[,2],selectedData_PP())
      colnames(C) <- c("Obs", "Modelo")

      boxplot(C, col=c("red","cyan"), xlab="Precipitación anual [mm]",
      horizontal=TRUE)
  })

Row {.tabset}

Temperatura

  uiOutput("dynamic3")

  output$dynamic3 <- renderUI({
    if (as.integer(input$Resolution) == 1) plotOutput("plot5")
    else plotOutput("plot6")
  })

  
  output$plot5 <- renderPlot({
    selectedData_T <- reactive({T_cc[, num()+3]})

    plot(unlist(selectedData_T()) ~ date, type="l",
        xlab="Fecha", ylab="Temperatura [°C]", col="green")
    for (i in 5:dim(T_cc)[2]){
      lines(unlist(T_cc[,i]) ~ date,
            col = rgb(red = 0.8275, green = 0.8275,
                      blue = 0.8275,alpha = 0.35),
            type = 'l')
    }
    lines(unlist(selectedData_T()) ~ date, type="l", col="green")
    grid()
  })
  
  output$plot6 <- renderPlot({
    selectedData_T <- reactive({T_cc_yr[, num()+1]})

    plot(unlist(selectedData_T()) ~ T_cc_yr$Año, type="l",
        xlab="Año", ylab="Temperatura [°C]", col="green")
    for (i in 2:dim(T_cc_yr)[2]){
      lines(T_cc_yr[,i] ~ T_cc_yr$Año,
            col = rgb(red = 0.8275, green = 0.8275,
                      blue = 0.8275,alpha = 0.35),
            type = 'l')
    }
    lines(unlist(selectedData_T()) ~ T_cc_yr$Año, type="l", col="green")
    lines(T_obs_yr, type="l", col="red", lty = 2)
    grid()
    legend("bottomright", legend=c("Modelo", "Observado", "Serie de Modelos"),
           col=c("green","red","grey"),lty=c(1,2,1), cex=0.8)
  })

Precipitaciones

  uiOutput("dynamic4")

  output$dynamic4 <- renderUI({
    if (as.integer(input$Resolution) == 1) plotOutput("plot7")
    else plotOutput("plot8")
  })

  
  output$plot7 <- renderPlot({
    selectedData_PP <- reactive({PP_cc[, num()+3]})

    plot(unlist(selectedData_PP()) ~ date, type="l",
        xlab="Fecha", ylab="Precipitación [mm]", col="cyan")
    for (i in 5:dim(PP_cc)[2]){
      lines(unlist(PP_cc[,i]) ~ date,
            col = rgb(red = 0.8275, green = 0.8275,
                      blue = 0.8275,alpha = 0.35),
            type = 'l')
    }
    lines(unlist(selectedData_PP()) ~ date, type="l", col="cyan")
    grid()
  })
  
  output$plot8 <- renderPlot({
    selectedData_PP <- reactive({PP_cc_yr[, num()+1]})

    plot(unlist(selectedData_PP()) ~ PP_cc_yr$Año, type="l",
        xlab="Año", ylab="Precipitación [mm]", col="cyan")
    for (i in 2:dim(PP_cc_yr)[2]){
      lines(PP_cc_yr[,i] ~ PP_cc_yr$Año,
            col = rgb(red = 0.8275, green = 0.8275,
                      blue = 0.8275,alpha = 0.35),
            type = 'l')
    }
    lines(unlist(selectedData_PP()) ~ PP_cc_yr$Año, type="l", col="cyan")
    lines(PP_obs_yr, type="l", col="red", lty = 2)
    grid()
    legend("topright", legend=c("Modelo", "Observado", "Serie de Modelos"),
           col=c("cyan","red","grey"),lty=c(1,2,1), cex=0.8)
  })
  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant