how to aggregate the same province/statename .I have tried couple of times by passing the given below line of code but it threw the error ,I think not having a numeric column caused to this error,if i am wrong ,please correct me and anyone could guide me through how to rectify this issue.
aggregate(. ~ total$province/state,data=total,fun=sum)
aggregate(total ,by=list(total$province/state,sum,na.rm=true)
I have tried switching the parameters in case of some kind of basic syntax error but that's not the issue ,I guess.
library(shiny)
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(DT)
##
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
##
## dataTableOutput, renderDataTable
COL = c("#293a80","#39375b","#6915cf","#4b8e8d","#d55252","#293462","#940a37","#f54291","#f0134d","#b22222","#3c4245","#5d1451","#3c3d47","#1a3e59","#233714","#3c6f9c","#1089ff","#394a6d","#3c70a4","#602080","#02383c","#5d5d5d","#543864","#042f4b","#293462","#4b8e8d","#d55252","#293462","#940a37","#f54291","#f0134d","#b22222")
#---
# deaths<-read.csv("C:/Users/dell/Downloads/archive (2)/time_series_covid_19_deaths.csv")
# confirmed<-read.csv("C:/Users/dell/Downloads/archive (2)/time_series_covid_19_confirmed.csv")
# recovered<-read.csv("C:/Users/dell/Downloads/archive (2)/time_series_covid_19_recovered.csv")
#total<-read.csv("C:/Users/dell/Downloads/archive (2)/test.csv")
#aggregate_value<-aggregate(total,by=list(total$Province.State),FUN = sum,na.rm=TRUE)
total<-data.frame(
stringsAsFactors = FALSE,
check.names = FALSE,
SNo = c(1L,2L,3L,4L,
5L,6L,7L,8L,9L,10L,11L,12L,13L,14L,15L,
16L,17L,18L,19L,20L,21L,22L,23L,24L,25L,
26L,27L,28L,29L,30L,31L,32L,33L,34L,35L,
36L,37L,38L,39L,40L,41L,42L,43L,44L,45L,
46L,47L,48L),
ObservationDate = c("1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/22/2020","1/22/2020",
"1/22/2020","1/22/2020","1/23/2020",
"1/23/2020","1/23/2020","1/23/2020","1/23/2020",
"1/23/2020","1/23/2020","1/23/2020","1/23/2020",
"1/23/2020"),
`Province/State` = c("Anhui",
"Beijing","Chongqing","Fujian","Gansu","Guangdong",
"Guangxi","Guizhou","Hainan","Hebei",
"Heilongjiang","Henan","Hong Kong","Hubei","Hunan",
"Inner Mongolia","Jiangsu","Jiangxi","Jilin",
"Liaoning","Macau","Ningxia","Qinghai","Shaanxi",
"Shandong","Shanghai","Shanxi","Sichuan",
"Taiwan","Tianjin","Tibet","Washington","Xinjiang",
"Yunnan","Zhejiang",NA,NA,NA,"Anhui",
"Beijing","Chongqing","Fujian","Gansu","Guangdong",
"Guangxi","Guizhou","Hainan","Hebei"),
`Country/Region` = c("Mainland China",
"Mainland China","Mainland China",
"Mainland China","Mainland China","Mainland China",
"Mainland China","Mainland China","Mainland China",
"Mainland China","Mainland China","Mainland China",
"Hong Kong","Mainland China","Mainland China",
"Mainland China","Mainland China","Mainland China",
"Mainland China","Mainland China","Macau",
"Mainland China","Mainland China","Mainland China",
"Mainland China","Mainland China",
"Mainland China","Mainland China","Taiwan","Mainland China",
"Mainland China","US","Mainland China",
"Mainland China","Mainland China","Japan","Thailand",
"South Korea","Mainland China","Mainland China",
"Mainland China","Mainland China",
"Mainland China","Mainland China","Mainland China",
"Mainland China","Mainland China","Mainland China"),
Last.Update = c("1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/22/2020 17:00",
"1/22/2020 17:00","1/23/2020 17:00","1/23/2020 17:00",
"1/23/2020 17:00","1/23/2020 17:00","1/23/2020 17:00",
"1/23/2020 17:00","1/23/2020 17:00",
"1/23/2020 17:00","1/23/2020 17:00","1/23/2020 17:00"),
Confirmed = c(1L,14L,6L,1L,
0L,26L,2L,1L,4L,1L,0L,5L,0L,444L,4L,0L,
1L,2L,0L,2L,1L,1L,0L,0L,2L,9L,1L,5L,
1L,4L,0L,1L,0L,1L,10L,2L,2L,1L,9L,22L,
9L,5L,2L,32L,5L,3L,5L,1L),
Deaths = c(0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,17L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,1L),
Recovered = c(0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,28L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
0L,2L,0L,0L,0L,0L)
)
#---
ui<-fluidPage(
fluidRow(plotlyOutput("plott1")),
fluidRow(plotlyOutput("plott2")),
fluidRow(plotlyOutput("plott3")),
fluidRow(dataTableOutput("x2"))
)
server<-function(input,output,session){
output$plott1 <- renderPlotly({
layout <- list(
font = list(size = 12),
title = "sonography for other-state",
xaxis = list(title = "district(other-state)"),
yaxis = list(title = "sonography records",automargin = TRUE)
)
p <- plot_ly(total, x = total$Province.State, y = total$Confirmed, type = 'bar', name = 'rajasthan', source = 'link1',marker = list(color = COL)) %>%
layout(yaxis = list(title = 'sonography block_level'),xaxis = list(title = 'Block name'),title='Sonograhy For Rajasthan')
})
output$plott2 <- renderPlotly({
d<-event_data('plotly_click',source = 'link1')
if(is.null(d)==F){
layout <- list(
font = list(size = 12),
title = "sonography for other-state",
xaxis = list(title = "district(other-state)"),
yaxis = list(title = "sonography records",automargin = TRUE)
)
p <- plot_ly(total, colors = COL, marker = list(color = COL),source = "link10") %>%
add_trace(x = total$Country.Region, y = total$Confirmed,name = "",type = 'bar') %>%
layout(font = layout$font, title = layout$title, xaxis = layout$xaxis, yaxis = layout$yaxis)
}
else
{
return(NULL)
}
})
output$plott3 <- renderPlotly({
d<-event_data('plotly_click',source = 'link10')
if(is.null(d)==F){
p <- plot_ly(total, x = total$Country.Region, y =total$Deaths , type = 'bar', name = 'rajasthan',source = "hey",
marker = list(color = '#1a3e59',
line = list(color = 'rgba(246, 78, 139, 1.0)'))) %>%
layout(barmode = 'stack',
xaxis = list(title = "Centre Data"),
yaxis = list(title ="Centre Name"))}
else{return(NULL)}
})
output$x2 <- DT::renderDataTable({
d<-event_data('plotly_click',source='hey')
if(is.null(d)==F){
subdata <- select(total$ObservationDate,total$Province.State,total$Country.Region,total$Last.Update,total$Confirmed,total$Deaths,total$Recovered)
DT::datatable(extensions = 'Buttons',subdata[,],options = list(dom = 'Blfrtip',
buttons =
list('copy', 'print', list(
extend = 'collection',
buttons = c('csv', 'excel', 'pdf'),
text = 'Download'
)),initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'background-color': '#090057', 'color': '#fff'});",
"}"),lengthMenu = c(5,10,15,20), pageLength = 10,scrollX = TRUE),class = "nowrap cell-border hover stripe",editable = FALSE)
}
else{
return(NULL)
}
})
}
shinyApp(ui,server)