input - Error: replacement has 1 row, data has 0 (R shiny error) -
i have been trying use daterange , checkbox input have 2 filtering options data. after filtering, have computed values meaningful information. after that, used dt package visualize , shinydashboard put on website.
it worked fine daterange input. gave me error title after have added checkbox option additional filtering. used modulation.
i trying fix error having hard time here.
here code
the added line think causing problem in module part, looking @ reactive function filters data checkbox input.
the error says "replacement has 1 row, data has 0"
i glad if problem fixed.
i appreciate time , helps!
ui
ui <- dashboardpage( title = "service management process dashboard" , skin = "purple" , dashboardheader(title = "it processes") , dashboardsidebar( sidebarmenu( id = "tabs" , menuitem("incident management", tabname = "incidentmanagement", icon = icon("change")) ) ) , dashboardbody( useshinyjs() , tabitems( tabitem( tabname = "incidentmanagement" ## begin incident management , box( daterangemonthsinput("imdaterange_incidentmanagement", "select date range:", # start = sys.date()-366, start = absmindate, end = sys.date()+1, min = absmindate, # min = sys.date()-366, max = sys.date()+1, format = "yyyy-mm", minviewmode = "months") ,checkboxgroupinput('checkbox', 'select avp:', unique(incidenttickets$requestoravp),selected = unique(incidenttickets$requestoravp), inline = true) , h3(class='bodycopy', "number of incidents created , client surveys returned") , width=350 , numberofticketscreatedui("incidentmgttag") , h3(class="bodycopy", "process performance") , incidentmgtprocessperformanceui("incidentmgtprocessperformancetag") ) ) ) ) )
server
server <- function(input, output, session) { callmodule(numberofticketscreatedoutput, id = "incidentmgttag", conn, reactive(input$imdaterange_incidentmanagement)) } shinyapp(ui = ui, server = server)
module
numberofticketscreatedui <- function(id) { ns <- ns(id) dt::datatableoutput(outputid = ns("numberofticketscreated")) } numberofticketscreatedoutput <- function(input, output, session, conn, daterange) { incidentticketsdata <- incidenttickets[,c(1,2,5,6)] limitdaterange <- reactive({ #filtering data using checkbox , date range inputs numberofincidenttickets <- incidentticketsdata[incidentticketsdata$requestoravp %in% c(input$checkbox),] numberofincidenttickets <- subset(numberofincidenttickets, createddatelocal >= daterange()[1] & createddatelocal <= daterange()[2]) #formatting date computation numberofincidenttickets$createddatelocal <- ymd(substring(numberofincidenttickets$createddatelocal, first = 1, last = 10)) numberofincidenttickets$createddatelocal <- format(as.date(numberofincidenttickets$createddatelocal), "%y-%m") #formatting columns computation numberofincidenttickets$ticketid <- 1 numberofincidenttickets$`tdsurveys ticketid`[!is.na(numberofincidenttickets$`tdsurveys ticketid`)] <- 1 numberofincidenttickets$`tdsurveys ticketid` <- as.numeric((numberofincidenttickets$`tdsurveys ticketid`)) #summing grouping month numberofincidenttickets.numb <- aggregate(cbind(numberofincidenttickets$ticketid)~createddatelocal, data = numberofincidenttickets, fun=sum) numberofincidenttickets.sur <- aggregate(cbind(numberofincidenttickets$`tdsurveys ticketid`)~createddatelocal, data = numberofincidenttickets, fun=sum) numberofincidenttickets.monthly <- merge(numberofincidenttickets.numb,numberofincidenttickets.sur, by="createddatelocal",all=true) # let's tip thingie on it's side numberofincidenttickets.monthly <- t(numberofincidenttickets.monthly) return(numberofincidenttickets.monthly) }) # plot data output$numberofticketscreated <- dt::renderdatatable({ #recall reactive table numberofticketscreateddata <- limitdaterange() colnames(numberofticketscreateddata) = numberofticketscreateddata[1, ] # set first row (months) header numberofticketscreateddata <- data.frame(numberofticketscreateddata, check.names = false) numberofticketscreateddata = numberofticketscreateddata[-1, ] # remove first row (so don't have months in table too) #needed compuation below indx <- sapply(numberofticketscreateddata, is.factor) numberofticketscreateddata[indx] <- lapply(numberofticketscreateddata[indx], function(x) as.numeric(as.character(x))) #computation change values numberofticketscreateddata$monthchange <- paste(round((numberofticketscreateddata[,13] - numberofticketscreateddata[,12]) / numberofticketscreateddata[,12] * 100,0),'%',sep = "") numberofticketscreateddata$yearchange <- paste(round((numberofticketscreateddata[,13] - numberofticketscreateddata[,1]) / numberofticketscreateddata[,1] * 100,0),'%',sep = "") #set row names row.names(numberofticketscreateddata) <- c("incident count","surveys count") #plot table using dt numberofticketscreateddatatable <- datatable(data = numberofticketscreateddata, class = 'nowrap', extensions=c('fixedcolumns','fixedheader') , options = list(blengthchange = false , bfilter = false , binfo = false , ordering = false , bpaginate = false , scrollx = true , fixedcolumns = list(leftcolumns=1, rightcolumns=0) , fixedheader = false , autowidth = false , columndefs = list(list(classname = 'dt-center', targets = c(1:ncol(numberofticketscreateddata)), width = '200px', targets = c(0))) , list(width = '50px', targets = c(1:ncol(numberofticketscreateddata)))) #, columndefs = list(list(classname = 'dt-center', targets = c(1:ncol(numberofticketscreateddata)), width = '200px', targets = c(0)))) ) return(numberofticketscreateddatatable) }) }
Comments
Post a Comment