I have been trying to get the if statement working so that I can convert the selectInputs into values that can be displayed into my DataTable but have not been able to achieve this. I tried by making it into a function that uses the selectInput to update it inside an eventreactive but had no luck since when the code is run my main panel goes blank (without displaying any errors). I tried using a function since this worked the first time I tried it with tasa_ftp. Can somebody help me with this?
# Define UI for FTP minimum
ui <- fluidPage(
# Application title
titlePanel("Tasa Minima"),
# Sidebar with a numeric and select inputs
sidebarLayout(
sidebarPanel(
numericInput("plazo",
label = "Plazo en Anos:",
min = 1,
max = 10000,
value = 5),
numericInput("tasa",
label = "Tasa Proyectada",
min = 1,
max = 50,
value = 10 ),
selectInput(
inputId = "banca",
label = "Banca Correspondiente",
choices = c("Banca Juridica", "Banca Personas"),
selected = "Banca Juridica",
multiple = FALSE,
selectize = FALSE,
width = NULL,
size = NULL
),
actionButton(inputId = "input_action", label = "Mostrar Resultados")
),
# Show a Data Table that updates through user inputs
mainPanel(
dataTableOutput("tasaminima")
)
)
)
# Functions
tasa_ftp_minima <- function(tasa,a){
C <- tasa/100
y <- 0.0348
m <- 365*a
k <- m/a
p <- 100
df <- data.frame(t = seq(1,m,1),CF = C/k*p + c(rep.int(0,m-1),p))
df$DF <- 1/(1+y/k)^(df$t)
df$DC <- df$DF*df$CF
P0 <- sum(df$DC)
df$TDC <- df$t*df$DC
STDC <- sum(df$TDC)
dur <- STDC/P0
a <- -0.000000001
b <- 0.000009
c <- 0.0311
tasa_ftp <- signif((a*dur^2+b*dur+c)*100)
}
ctos_completos <- function(descripcion){
if(descripcion == "Banca Juridica"){
ctos <- as.numeric(0.0226)
return(ctos)
} else{
if(descripcion == "Banca Personas"){
ctos <- as.numeric(0.7057)
return(ctos)
}
}
}
# Server
server <- function(input, output) {
tasa_ftp <- eventReactive(input$input_action,{
tasa_ftp_minima(input$tasa,input$plazo)
})
ctos <- eventReactive(input$input_ction,{
ctos_completos(as.character(input$banca))
})
pe <- 3.5
output$tasaminima <- renderDataTable({
data.frame(Componentes = c("Tasa FTP", "Perdida Esperada", "ABC Costing","Tasa FTP Minima"),
Resultado = c(tasa_ftp(),pe,ctos(),round(tasa_ftp()+pe+ctos(),2)))
})
}
# Run the application
shinyApp(ui = ui, server = server) ```