I have this piece of code where error happens:
server <- function(input, output, session) {
rvalues <- reactiveValues()
observeEvent(input$run, {
alldata <- data_request(as.numeric(input$text1))
fields <- alldata$fields
fields <- as.data.table(do.call(rbind, fields))
setnames(fields,
c("V1", "V2", "V3", "V4", "V5"),
c('mod_id', 'fieldas', 'neturima', 'alternatyva', 'score'))
rvalues$fields <- fields
scores <- alldata$scores
scores <- as.data.table(do.call(rbind, scores))
setnames(scores,
c("V1", "V2"),
c("mod_id", "score"))
rvalues$scores <- scores
info <- alldata$info
info <- as.data.table(do.call(rbind, info))
setnames(info,
c('V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7'),
c('prod_id', 'mod_id', 'title', 'sell_price', 'cost_price', 'delivery_hours', 'score'))
rvalues$info <- info
rvalues$choices <- paste0('[',info$score, ']', '[', info$mod_id, ']', substr(info$title,
start = 1,
stop = 100),
'...')
#print(class(rvalues$choices))
updateSelectInput(session, 'selectinput', choices = rvalues$choices)
})
}
My program asks for an item id and then downloads the data from mysql server. It works fine if the provided id exists, but if you type in an unexisting id, then the whole thing crashes near the first do.call
statement:
Warning: Error in do.call: second argument must be a list
What I want to achieve is to check if this error comes up and if id does, I want my custom error message to come up and skip the rest of the code in current observeEvent
.
I tried to put:
a <- tryCatch(warning("Wrong product id!"), warning=function(w) { w })
mess <- a$message
showNotification(mess)
after the first do.call
statement, but that just shows the warning even if the id is correct and the app still crashes if the id is wrong...