无法在为闪亮的变量添加 selectInput 选项时渲染绘图,否则运行完全正常

问题描述

当我加入几个数据框时,运行相关,然后在 rmarkdown 中绘制它们,然后它工作

但同样的事情是无法正常工作并在使用 selectInput 选择相关变量时出错:

summarise() 输入 COR 有问题。 [31mx[39m 不兼容] 尺寸 [34mi[39m 输入 CORcor(Confirmed_daily,as.numeric(input$id_vaccination_type))。 [34mi[39m 错误] 发生在第 2 组:Country.Region = "Argentina"。

数据:

library(tidyverse)
library(lubridate)
library(glue)
library(scales)
library(tidytext)
library(shiny)
library(shinydashboard)

file_url1 <- "https://raw.githubusercontent.com/johnsNow09/covid19-df_stack-code/main/ts_all_long4.csv"

file_url2 <- "https://raw.githubusercontent.com/johnsNow09/covid19-df_stack-code/main/vaccination_data.csv"

ts_all_long <- read.csv(url(file_url1))
vaccination_data <- read.csv(url(file_url2))

ts_all_long <- ts_all_long %>%
  mutate(date = as.Date(date))

vaccination_data <- vaccination_data %>%
  mutate(date = as.Date(date))

当我使用上述数据进行绘图时,它会起作用:

ts_all_long %>% 
  left_join(y = vaccination_data,by = c("Country.Region" = "location","date","continent","iso3c" = "iso_code")) %>% 
  
  na.omit() %>% 

  group_by(Country.Region) %>% 

  summarise(COR = cor(Confirmed_daily,total_vaccinations),total_vaccinations_per_hundred = first(total_vaccinations_per_hundred)) %>% 
  
  
  arrange(COR) %>% 
  na.omit() %>% 
  slice(c(1:15,( n()-14): n() )) %>% 
  
  ggplot(aes(x = COR,y = fct_reorder(Country.Region,-COR),col = COR > 0))  +
  geom_point(aes(size = total_vaccinations_per_hundred)) +
  geom_errorbarh(height = 0,aes(xmin = COR,xmax = 0)) +
  geom_vline(xintercept = 0,col = "midnightblue",lty = 2,size = 1) +
  
  theme(
        panel.grid.major = element_blank(),legend.position = "NULL") +
  
  labs(title = glue("Top Countries by +/- Correlation with Vaccination as of {max(vaccination_data$date)}"),subtitle = "Size is proportional to Vaccination per Population",y = "",x = "Correlation",caption = "Data source: covid19.analytics
       Created by: ViSa")

enter image description here

问题:当我在 shiny 中将其与 SelectInput 一起用于 total_vaccinations 时,它会出错。

用户界面

fluidRow(
                 style = "border: 1px solid gray;",h3("Vaccination to Cases Correlation Analysis"),column(4,style = "border: 1px solid gray;",selectInput(inputId = "id_vaccination_type",label = "Choose Vaccination Parameter",choices = c("total_vaccinations","people_vaccinated","people_fully_vaccinated"),selected = "total_vaccinations")
                        ),column(8,plotOutput("top_corr_countries",height = "550px") #
                 )

服务器

output$top_corr_countries <- renderPlot({
        
        ts_all_long %>% 
            left_join(y = vaccination_data,"iso3c" = "iso_code")) %>% 
            
            na.omit() %>% 
            
            group_by(Country.Region) %>% 
            
            summarise(COR = cor(Confirmed_daily,as.numeric(input$id_vaccination_type)),total_vaccinations_per_hundred = first(total_vaccinations_per_hundred)) %>% 
             
            arrange(COR) %>% 
            na.omit() %>% 
            slice(c(1:15,( n()-14): n() )) %>% 
            
            ggplot(aes(x = COR,col = COR > 0))  +
            geom_point(aes(size = total_vaccinations_per_hundred)) +
            geom_errorbarh(height = 0,size = 1,xmax = 0)) +
            geom_vline(xintercept = 0,size = 1) +
            
            theme(
                panel.grid.major = element_blank(),legend.position = "NULL") +
            
            labs(title = glue("Top Countries by +/- Correlation with Vaccination as of {max(vaccination_data$date)}"),caption = "Data source: covid19.analytics
       Created by: ViSa")
        
    })

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)