Problem trying to publish a plot into shinyapps.io

39 Views Asked by At

I am having some problems publishing my shinny app online which consists of a fairly simple plot. The entire r code I have tried is the following:

library(ggtext)
library(dplyr)
library(ggplot2)
library(readxl)
library(dplyr)
library(tidyr)
library(patchwork)
library(hrbrthemes) 
library(ggbump) 
library(httpgd)
library(writexl)
library(here)
#library(shiny)
library(ggplot2)
library(dplyr)
library(scales)

#getwd()

############################################################################
### Importing Datasets for Budget Constraing Analysis. #####################

Panel <- read.csv2("Consolidated BC LATAM.csv", header = TRUE)
##############################################################################


Data <- Panel %>%
  select(1:23)

glimpse(Data)

Data <- Data %>%
  mutate(`domestic debt` = as.numeric(domestic.debt ),
         `change in foreign debt` = as.numeric(change.in.foreign.debt),
         `change in total debt` = as.numeric(change.in.total.debt),
         `change in real money balance` = as.numeric(change.in.real.money.balance),
         `Inflation Tax` = as.numeric(Inflation.Tax),
         seigniorage = as.numeric(seigniorage),
         `primary deficit` = as.numeric(primary.deficit)) 


Data <- Data %>%
  mutate(Criterion_Dummy = ifelse(`change in total debt` <= 0 & seigniorage > 0 & `primary deficit` <= 0, 1, 0)) 

# Define UI
ui <- fluidPage(
  titlePanel("Criterion and Inflation Rate Visualization"),
  sidebarLayout(
    sidebarPanel(
      selectInput("country", "Select Country:",
                  choices = unique(outcome$Country),
                  selected = unique(outcome$Country)[1]),
      sliderInput("x_range", "X-Axis Range:",
                  min = 1960, max = 2020, value = c(1960, 2020))
    ),
    mainPanel(
      plotOutput("plot")
    )
  )
)

# Define server logic
server <- function(input, output) {
  
  filtered_data <- reactive({
    filter(outcome, Country == input$country & 
             year >= input$x_range[1] & year <= input$x_range[2])
  })
  
  output$plot <- renderPlot({
    ggplot(filtered_data(), aes(x = year, 
                                y = as.numeric(`Inflation Rate`),
                                color = factor(Criterion_Dummy),
                                group = 1)) +
      geom_point(alpha = 0.5) +
      geom_line() +
      geom_point(data = filtered_data() %>% filter(!is.na(`Stabilization Plan`)), 
                 aes(label = `Stabilization Plan`), 
                 alpha = 1, size = 4) +
      geom_text(data = filtered_data() %>% filter(!is.na(`Stabilization Plan`)), 
                aes(label = `Stabilization Plan`, 
                    x = year, 
                    y = as.numeric(`Inflation Rate`)), 
                hjust = -0.1, vjust = -0.5, size = 4) +
      labs(x = "Year", y = "Inflation Rate") +
      facet_wrap(~ Country) + 
      theme_ipsum() +
      scale_color_manual(name = "Criterion Dummy",  # Change legend title
                         labels = c("0" = "Criterion not met", "1" = "Fiscal Surplus + Positive Seigniorage + Debt Reduction"),  # Change legend labels
                         values = c("0" = "#FF5733", "1" = "#3498DB")) +
      theme(legend.position = "bottom")
  })
}

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

I am aware of all the other questions similar to this one but non have helped. At first I thought it was a problem with the data upload but I after fixing that and turning the excel file into a csv the problem persists. Naturally the app works perfectly fine locally so I have no idea what could be causing this inconvenience.

I have been trying to publish a simple plot into shiny.io but I am not being able to.

0

There are 0 best solutions below