I am trying to run this package https://github.com/beerda/crudtable. The package works via live demo link https://beerda.shinyapps.io/crudtable/ on that site.
library(shiny)
library(crudtable)
# Data Access Object from the CO2 data frame
dao <- dataFrameDao(CO2)
# User Interface
ui <- fluidPage(
crudTableUI('crud')
)
# Server-side
server <- function(input, output, session) {
crudTableServer('crud', dao)
}
# Run the shiny app
shinyApp(ui = ui, server = server)
But when I try to start it from my RStudio R Version 4.2
The program starts but crashes after clicking the + New Record
button with the Error:
Warning: Error in if: the condition has length > 1 1: runApp
What does this error stand for and how can I solve it?
After some debugging I could track down the bug. The simpleFormUIFactory
is faulty. There we test for the type of an attribute like so:
if (a$type == "factor") {
# ...
}
The problem is that with the example dataset the class of column Plant
is
class(CO2$Plant)
# [1] "ordered" "factor"
i.e. it contains 2 elements. With R 4.2.0
the behaviour of using if
with conditions of length greater then 1 changed to throw an error instead of a warning (cf. to the corrsponding section in the NEWS
for R 4.2.0.
), i.e. something like
if (1 == 1:2) 1
throws an error in R >= 4.2.0
and was a warning before. (This explains why it works for the demo but not for you).
Having said that, until this bug is patched, you have basically 2 options:
simpleFormUIFactory
in the first place. (cf. to the help of crudTableServer
for an example)ordered
to normal factor
:CO2$Plant <- factor(CO2$Plant, ordered = FALSE)
P.S.: The package author should replace ==
in the if
clause by a %in%
. I will post a comment in your issue post.