R скрипт работает, почему график в shinyio пустой

#r #shinyapps

#r #блестящие приложения

Вопрос:

Я наконец-то заработал свой R-скрипт. Извините, если вы видели более раннее сообщение о помощи, я обнаружил орфографическую ошибку, а затем исправил то, как я называю свои переменные в aes. Однако, когда я запускаю его как приложение shinyapp, я получаю макет, который я ожидаю, без сообщения об ошибке, но сюжет пуст. Есть идеи, почему это происходит ? Спасибо

Вот мой код:

 CountrySetslt;-c("select","G7","G20","OECD")  OECDcomparatorlt;-c("per_capita","perc_GDP")  ##  CountrySetListlt;-list(select=select_countries,G7=G7coun,G20=G20coun,OECD=OECD_CDNpercap_tot_ave$Country)  ##  # Define UI for app that draws plots ----  ui lt;- fluidPage(  # App title ----  titlePanel("Canadian Healthcare Spending"),  # Make the Sidebar layout  sidebarLayout(  # Put in the sidebar all the input functions  sidebarPanel(  tabsetPanel(id="tabs",  tabPanel("Country Comparison",br(),   p("On this tab you can compare the overall canadian spending to different countries"),  selectInput('CountrySets','countries of interest',names(CountrySetList),selected="select"),  selectInput('OECDcomparator','metric',OECDcomparator,selected="per_capita"),  # Add comment  p("data was obtained from https://data.oecd.org/healthres/health-spending.htm ")),  tabPanel("Provinces",br(),  p("On this tab you can compare the overall spending of different provinces"))  )  ),  mainPanel(  conditionalPanel(condition="input.tabs == 'Country Comparison'",  plotOutput('plotC')  ),  conditionalPanel(condition="input.tabs == 'Provinces'",  #plotOutput('plot2')  br()  )  )# end mainPanel    ) # end sidebarLayout  ) # end fluidPage    # done setting up user interface  # ========================= SERVER ####  server lt;- function(input, output){  CountrySetslt;-reactive({  input$CountrySets})  #  OECDcomparatorlt;-reactive({  input$OECDcomparator})  ##  output$plotC lt;- renderPlot({  setlt;-CountrySets()  Selected_Countrieslt;-CountrySetList[[set]]  OECDcomparatorlt;-OECDcomparator()  dflt;-subset(OECD_CDNpercap_tot_aveplsGDP,OECD_CDNpercap_tot_aveplsGDP$Country%in%Selected_Countries)  meanlt;-mean(df[[OECDcomparator]])  df$Countrylt;-reorder(df$Country,df[[OECDcomparator]])  #  plotClt;- ggplot(df, aes(x=Country, y=!!sym(OECDcomparator),label=round(!!sym(OECDcomparator))))    geom_col(stat='identity', aes(fill=Can))    geom_hline(yintercept=mean,linetype="dashed")   scale_fill_manual(values=c("red","grey"))     geom_text(color="black",size=4,hjust=1)   annotate("text",x=0,y=mean,label =paste(set,"average",round(mean)),   size=5,check_overlap = TRUE,hjust=0,vjust=-1)   labs(fill="Country")   ggtitle("Canada's per capita spending in comparison n to select countries ")   ylab(paste(OECDcomparator,"spending"))   xlab("")   coord_flip()   guides(fill=FALSE)   theme_bw()   theme(axis.text = element_text(size = 12),  axis.title = element_text(size = 12),  legend.text=element_text(size=12),strip.text = element_text(size = 12),  legend.title = element_blank(),plot.title=element_text(size=14,face = "bold"))  })#end of plotC  } # end of server  ###  shinyApp(ui=ui,server=server)  

Вот мои данные:

 dput(CountrySetList) list(select = c("IND", "IDN", "CHN", "ZAF", "MEX", "TUR", "BRA",  "RUS", "KOR", "ITA", "GBR", "JPN", "AUS", "FRA", "CAN", "DEU",  "USA", "NOR", "NLD", "AUT", "BELG"), G7 = c("CAN", "JPN", "FRA",  "ITA", "GBR", "USA", "DEU"), G20 = c("MEX", "CHN", "BRA", "IND",  "IDN", "AUS", "ZAF", "TUR", "SAU", "ARG", "RUS", "KOR", "FRA",  "JPN", "DEU", "CAN", "ITA", "GBR", "USA", "SGP", "EU", "NGA",  "NLD", "DNK", "SWE", "AUT", "BEL", "IRL", "ESP", "POL", "HUN",  "CZE", "SVK", "SVN", "BGR", "LTU", "EST"), OECD = structure(c(36L,  44L, 41L, 12L, 8L, 40L, 48L, 17L, 3L, 6L, 9L, 22L, 27L, 46L,  42L, 28L, 20L, 32L, 39L, 34L, 19L, 14L, 15L, 2L, 1L, 37L, 33L,  23L, 29L, 35L, 24L, 21L, 38L, 13L, 5L, 30L, 45L, 47L, 31L, 18L,  25L, 10L, 11L, 16L, 26L, 43L, 7L, 49L, 4L), .Label = c("IND",  "IDN", "CHN", "ZAF", "MEX", "COL", "TUR", "BRA", "CRI", "ROU",  "RUS", "BGR", "LVA", "HRV", "HUN", "SVK", "CHL", "POL", "GRC",  "EST", "LTU", "CYP", "ISR", "KOR", "PRT", "SVN", "CZE", "ESP",  "ITA", "MLT", "NZL", "FIN", "ISL", "GBR", "JPN", "AUS", "IRL",  "LUX", "FRA", "CAN", "BEL", "DNK", "SWE", "AUT", "NLD", "DEU",  "NOR", "CHE", "USA"), class = "factor", scores = structure(c(AUS = 6078.94112,  AUT = 7080.932352, BEL = 6706.35808, BGR = 2213.4896, BRA = 1824.00608,  CAN = 6681.30592, CHE = 8893.00832, CHL = 2743.006464, CHN = 942.641493333333,  COL = 1508.04256, CRI = 1922.1024, CYP = 3193.62016, CZE = 4080.563968,  DEU = 7979.544064, DNK = 6803.6032, ESP = 4324.19552, EST = 3085.181696,  FIN = 5611.070464, FRA = 6628.256256, GBR = 5668.214272, GRC = 2904.19008,  HRV = 2353.02176, HUN = 2647.1408, IDN = 419.776426666667, IND = 307.127466666667,  IRL = 6350.11072, ISL = 5636.817408, ISR = 3484.8016, ITA = 4517.1136,  JPN = 5746.82912, KOR = 3957.469696, LTU = 3177.325056, LUX = 6556.35264,  LVA = 2302.95008, MEX = 1446.171136, MLT = 4677.66101333333,  NLD = 7148.905472, NOR = 8235.11424, NZL = 5070.56448, POL = 2811.121408,  PRT = 3975.710208, ROU = 1991.72256, RUS = 2077.27328, SVK = 2716.916992,  SVN = 3984.64896, SWE = 6939.910912, TUR = 1531.34976, USA = 13235.32544,  ZAF = 1379.19018666667), .Dim = 49L, .Dimnames = list(c("AUS",  "AUT", "BEL", "BGR", "BRA", "CAN", "CHE", "CHL", "CHN", "COL",  "CRI", "CYP", "CZE", "DEU", "DNK", "ESP", "EST", "FIN", "FRA",  "GBR", "GRC", "HRV", "HUN", "IDN", "IND", "IRL", "ISL", "ISR",  "ITA", "JPN", "KOR", "LTU", "LUX", "LVA", "MEX", "MLT", "NLD",  "NOR", "NZL", "POL", "PRT", "ROU", "RUS", "SVK", "SVN", "SWE",  "TUR", "USA", "ZAF")))))   dput(OECD_CDNpercap_tot_aveplsGDP) structure(list(Country = structure(1:49, .Label = c("AUS", "AUT",  "BEL", "BGR", "BRA", "CAN", "CHE", "CHL", "CHN", "COL", "CRI",  "CYP", "CZE", "DEU", "DNK", "ESP", "EST", "FIN", "FRA", "GBR",  "GRC", "HRV", "HUN", "IDN", "IND", "IRL", "ISL", "ISR", "ITA",  "JPN", "KOR", "LTU", "LUX", "LVA", "MEX", "MLT", "NLD", "NOR",  "NZL", "POL", "PRT", "ROU", "RUS", "SVK", "SVN", "SWE", "TUR",  "USA", "ZAF"), class = "factor"), per_capita = c(6078.94112,  7080.932352, 6706.35808, 2213.4896, 1824.00608, 6681.30592, 8893.00832,  2743.006464, 942.641493333333, 1508.04256, 1922.1024, 3193.62016,  4080.563968, 7979.544064, 6803.6032, 4324.19552, 3085.181696,  5611.070464, 6628.256256, 5668.214272, 2904.19008, 2353.02176,  2647.1408, 419.776426666667, 307.127466666667, 6350.11072, 5636.817408,  3484.8016, 4517.1136, 5746.82912, 3957.469696, 3177.325056, 6556.35264,  2302.95008, 1446.171136, 4677.66101333333, 7148.905472, 8235.11424,  5070.56448, 2811.121408, 3975.710208, 1991.72256, 2077.27328,  2716.916992, 3984.64896, 6939.910912, 1531.34976, 13235.32544,  1379.19018666667), Can = c("No", "No", "No", "No", "No", "CAN",  "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No",  "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No",  "No", "No", "No", "No", "No", "No", "No", "No", "No", "No", "No",  "No", "No", "No", "No", "No", "No", "No", "No", "No", "No"),   G7 = c("No", "No", "No", "No", "No", "G7", "No", "No", "No",   "No", "No", "No", "No", "G7", "No", "No", "No", "No", "G7",   "G7", "No", "No", "No", "No", "No", "No", "No", "No", "G7",   "G7", "No", "No", "No", "No", "No", "No", "No", "No", "No",   "No", "No", "No", "No", "No", "No", "No", "No", "G7", "No"  ), G20 = c("G20", "G20", "G20", "G20", "G20", "G20", "No",   "No", "G20", "No", "No", "No", "G20", "G20", "G20", "G20",   "G20", "No", "G20", "G20", "No", "No", "G20", "G20", "G20",   "G20", "No", "No", "G20", "G20", "G20", "G20", "No", "No",   "G20", "No", "G20", "No", "No", "G20", "No", "No", "G20",   "G20", "G20", "G20", "G20", "G20", "G20"), perc_GDP = c(9.272,   10.5974, 10.74525, 7.36675, 9.424, 10.877, 11.30575, 9.089,   5.05733333333333, 7.636, 7.2325, 6.7505, 7.7354, 11.6484,   10.1648, 9.00775, 6.898, 9.2484, 11.4984, 10.4986, 8.05525,   6.855, 6.66175, 2.94066666666667, 3.56866666666667, 7.0444,   8.643, 7.364, 8.8926, 10.8985, 7.619, 6.8414, 5.2775, 6.21875,   5.6068, 8.912, 10.3634, 10.5592, 9.07125, 6.607, 9.552, 5.36475,   5.393, 7.0316, 8.6362, 10.9892, 4.23325, 16.776, 8.154)), row.names = c(NA,  -49L), class = c("tbl_df", "tbl", "data.frame"))  

Комментарии:

1. Попробуйте удалить plotClt;- или добавить a return(plotC) , чтобы вернуть свой сюжет.

2. да, отлично, это сработало. Спасибо. Я отвечу на свой собственный вопрос, если у других возникнет та же проблема