Shinyapps.io error: Warning: Error in gsub: input string 31 is invalid in this locale

Shinyapps.io error: Warning: Error in gsub: input string 31 is invalid in this locale

美好的一天,过去几天我一直在使用我闪亮的应用程序,该应用程序在本地运行良好,但每当我在 shinyapps.io 上打开它时,它不会显示 plot_geo 地图。它只是说 Error: An error has occurred. Check your logs or contact app author for clarification .

这是我应用程序的 link。问题出在“世界二氧化碳排放量”地图上。

我也看到了类似的post here所以我尝试了这个解决方案,但问题仍然存在。

所以我检查了我的日志,这是我发现的:

2022-05-15T15:43:22.365650+00:00 shinyapps[6305171]: Warning: Error in gsub: input 
 string 31 is invalid in this locale
2022-05-15T15:43:22.365776+00:00 shinyapps[6305171]:   123: FUN
2022-05-15T15:43:22.365976+00:00 shinyapps[6305171]:   119: FUN
2022-05-15T15:43:22.365875+00:00 shinyapps[6305171]:   121: FUN
2022-05-15T15:43:22.365927+00:00 shinyapps[6305171]:   120: lapply
2022-05-15T15:43:22.366368+00:00 shinyapps[6305171]:    96: output$Map
2022-05-15T15:43:22.366025+00:00 shinyapps[6305171]:   118: lapply
2022-05-15T15:43:22.366573+00:00 shinyapps[6305171]:     7: connect$retryingStartServer
2022-05-15T15:43:22.366126+00:00 shinyapps[6305171]:   116: plotly_build.plotly
2022-05-15T15:43:22.366410+00:00 shinyapps[6305171]:    15: <Anonymous>
2022-05-15T15:43:22.366521+00:00 shinyapps[6305171]:     8: retry
2022-05-15T15:43:22.366280+00:00 shinyapps[6305171]:   110: func
2022-05-15T15:43:22.365718+00:00 shinyapps[6305171]:   124: gsub
2022-05-15T15:43:22.366327+00:00 shinyapps[6305171]:    97: renderFunc
2022-05-15T15:43:22.366177+00:00 shinyapps[6305171]:   112: 
getFromNamespace("prepareWidget", "plotly")
2022-05-15T15:43:22.366470+00:00 shinyapps[6305171]:    13: fn
2022-05-15T15:43:22.366229+00:00 shinyapps[6305171]:   111: shinyRenderWidget
2022-05-15T15:43:22.366077+00:00 shinyapps[6305171]:   117: translate_linebreaks
2022-05-15T15:43:22.366622+00:00 shinyapps[6305171]:     6: eval
2022-05-15T15:43:22.365825+00:00 shinyapps[6305171]:   122: lapply
2022-05-15T15:43:22.366670+00:00 shinyapps[6305171]:     5: eval

这是我的代码:

app.R

library(tidyverse)
library(rnaturalearth)
library(shiny)
library(plyr)
library(dplyr)
library(plotly)
library(ggplot2)
library(gganimate)
library(sf)
library(uuid)
library(shinydashboard)
library(fontawesome)


source("curl.R")
world <- ne_countries(scale = "small", returnclass = "sf")

#####################
worldEmission <- world %>% select(geometry,name,iso_a3) %>%
  right_join(data, by = c("iso_a3" = "ISO.3166.1.alpha.3" )) 
worldEmission <- worldEmission %>% mutate(selected = TRUE)

maxperCapita <- max(worldEmission$Per.Capita)
worldEmission[is.na(worldEmission)] = 0
worldContinents <- data1 %>% select(Entity, Continent) %>% 
  right_join(worldEmission, by = c("Entity" = "Country"))
worldContinents$Year <- as.numeric(worldContinents$Year)

countryNames <-unique(worldEmission$Country)

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


ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("World Co2 Emission", tabName = "Map", icon = icon('map')), 
      menuItem("Continent Co2 Emission", tabName = "Continent",icon = icon('chart-bar')),
      menuItem("Emission Factors", tabName = "Emission", icon = icon('chart-line')) ,
      menuItem("Linear Regression", tabName = "Regression", icon = icon('arrow-alt-circle-up')) 
    )
  ),
  dashboardBody(
    tabItems(
      tabItem("Map",
              h1("Map"),
              box(plotlyOutput("Map"), wdith = 3)
              ),
      tabItem("Continent",
              box(plotOutput("Bargraph"), wdith = 12)
              ),
      tabItem("Emission",
              box(plotOutput("Linegraph"), wdith = 12)
              ),
      tabItem("Regression",
              box(plotOutput("Linearregression"), wdith = 12)
              )
    )#tabItems
    
  )#dashboardBody
  
)#dashboardPage
      
      
server <- function(input, output) {
  
  output$Map <- renderPlotly({
    chorplethMap <- plot_geo(worldEmission,
                             locationmode = countryNames,
                             color = ("black"),
                            frame = ~Year) %>%
       add_trace(worldEmission,
                 type = "choropleth",
                 locations = ~iso_a3,
                z = ~Per.Capita,
                zmin = 0,
                color = ~Per.Capita,
                colorscale = 'reds') %>%
       layout(geo = list(scope = countryNames))
    chorplethMap
  })
  
  output$Bargraph <- renderPlot({
    
    worldContinents<-na.omit(worldContinents)
    barchart <- ggplot(data = worldContinents, 
                       aes(x = Continent, y = `Per.Capita`,fill = Continent)) +
      stat_summary(geom = "col", fun = mean, width= 0.7, col = "gray50") + 
      geom_bar(stat = "identity") +
      theme_light(base_size = 20) 
    barchart
  })
  
  output$Linegraph <- renderPlot({
    
    data2 <- na.omit(data)
    totalInYears <- aggregate(data2[c("Coal", "Oil", "Gas", "Cement")], by = data2["Year"], sum)
    
    linechart <- ggplot(data = totalInYears, aes(x = Year)) + 
      geom_line(aes(y = Coal), color = "orange", lwd = 1) +
      geom_line(aes(y = Oil), color = "pink",lwd = 1) +
      geom_line(aes(y = Gas), color = "yellow",lwd = 1) +
      geom_line(aes(y = Cement), color = "green",lwd = 1) + theme_dark()
    
    linechart
  })
  output$Linearregression <- renderPlot({
    
    linearRegression <- subset(data, select = c("Country", "Year", "Per.Capita"))
    linearRegression1 <- linearRegression[which(linearRegression$Country == 'Global'),]
    plot(linearRegression1$Year, linearRegression1$Per.Capita)
    linearRegression2 <- lm(Per.Capita ~ Year, data = linearRegression1)
    summary(linearRegression2)
    abline(linearRegression2, col = "blue")
    
    shapiro.test(linearRegression1$Per.Capita)
  })
}


shinyApp(ui = ui, server = server)

curl.R

library(curl)

x <- tempfile()
y <- tempfile()

curl_download("https://raw.githubusercontent.com/FrancisDiesto/CarbonEmmissionPerCapita/main/GCB2021v34_MtCO2_flat.csv", x)
data <- read.csv(x)

curl_download("https://raw.githubusercontent.com/FrancisDiesto/WorldPopulation/main/continents-according-to-our-world-in-data.csv", y)
data1 <- read.csv(y)

这应该是结果:

谢谢

我的朋友找到了解决方案,@monte 也指出了这一点,我只是在之前的尝试中使用了不同的语法,但这个有效Sys.setlocale("LC_ALL", "C")谢谢。