Hello, i'm trying to load a environment with some functions that i want to apply in some variables that will be inputed by the user.
I tried three diffrent ways using load() and also try to use RDS but without success.
The initial idea was to apply the functions just for those with "1" for the value of the checkbox for respective company, but as i was already having problems just to print a result from a function, i trying to solve first how to include the result from the function in the output table. The error is "Warning: Error in data.frame: arguments imply differing number of rows: 1, 0
[No stack trace available]"
But i can't figure it out what is that mean
Follow the code:
#> Code comment
R_code <-
library(shiny)
library(DT)
#load("C:/Users/Filipe Chagas/Desktop/OneDrive/Motor.test/company_models.RData")
#app.R
ui <- fluidPage(
sidebarPanel(
h1("Multi-simulator test"),
numericInput("age","Age",18,min=18,max=90),
verbatimTextOutput("textAge"),
numericInput("dlage","Drive-license Age",1,min=1,max=80),
numericInput("pp","Power rate (Horsepower/Gross-Weight)",0.1,min=0.1,max=10),
numericInput("cc","Cilinders",1,min=1,max=10000),
numericInput("kids","Have kids? (yes=1,no=0)",0,min=0,max=1),
numericInput("car_year","Year of the car",1950,min=1950,max=3000),
numericInput("lisbon","Live in Lisbon? (yes=1,no=0)",0,min=0,max=1),
tags$hr(),
checkboxInput("CoA", "Company A", TRUE),
checkboxInput("CoB", "Company B", TRUE),
checkboxInput("CoC", "Company C", TRUE)),
mainPanel(
tableOutput("table")
)
)
server <- function(input, output) {
load("C:/Users/Filipe Chagas/Desktop/OneDrive/Motor.test/company_models.RData")
# Reactive value for selected dataset ----
#
# reactive({if(input$CoA==1){
# isolate(PremiumCoA <- CompanyA(input$age,input$dlage,input$pp,input$ywc))
# }})
#
data <- reactive({
#ifelse(input$CoA==1,premiumCoA<-CompanyA(input$age,input$dlage,input$pp,input$ywc),premiumCoA <- NA)
data.frame(Age=input$age,Car_Age=(2019 - input$car_year),
Dl_age=input$dlage,Power_rate=input$pp,
Cilinders=input$cc,Kids=input$kids,
Lisbon=input$lisbon,PremiumCoA=CompanyA(input$age,input$dlage,input$pp,input$ywc)
)})
# Table of selected dataset ----
output$table <- renderTable({
data()
})
}
shinyApp(ui = ui, server = server)
Company Models code:
#> Code comment
R_code <-
CompanyA <- function(age,dlage,pp,ywc){exp(0.2*as.numeric(age) + 0.35*as.numeric(dlage) + 0.03*as.numeric(pp) - 0.17*as.numeric(ywc) )}
CompanyB <- function(age,dlage,cc,kids){exp(0.15*as.numeric(age) + 0.28*as.numeric(dlage) + 0.48*as.numeric(cc) + 0.2*as.numeric(kids))}
CompanyC <- function(age,car_age,ywc,lisbon){exp(0.1*as.numeric(age) + 0.14*as.numeric(car_age) - 0.08*as.numeric(ywc) + 0.1*as.numeric(lisbon))}