【发布时间】:2017-09-09 23:53:42
【问题描述】:
我想调整我的摊销基金表的长度。问题是当我第一次运行应用程序及其公式时(例如计算 20 个周期),在下一次运行时,当我需要运行 10 个周期时,公式会覆盖计算,保留之前计算的值。
闪亮的代码是这样的:
#ui.r
library(shiny)
shinyUI(
fluidPage(
titlePanel("Fondo de Amortización"),
sidebarLayout(
sidebarPanel(numericInput(inputId = 'M',label = 'Monto',value = 2400000),
numericInput(inputId = 'n',label = 'Período',value = 20),
numericInput(inputId = 'i',label = 'Interés',value = 3.7)),
mainPanel(
tableOutput('x')))
))
#server.r
library(shiny)
shinyServer(function(input, output, session) {
options(digits = 7)
options(scipen = 999)
IR <<- numeric();CA <<- numeric();SF <<- numeric()
f.amort <- function(M,i,n) {
R <<- M*i/(((1 + i)**n)-1)
IR[1] <<- 0
IR[2] <<- R*i
CA[1] <<- R
SF[1] <<- R
for (k in 1:(n-1)) {
CA[k+1] <<- R + IR[k+1]
SF[k+1] <<- SF[k] + CA[k+1]
if (k < n-1){
IR[k+2] <<- SF[k+1]*i
}
}
}
output$x <- renderTable({
f.amort(input$M, input$i/100, input$n)
tabla <- rbind((cbind("Rent" = c(R, recursive=TRUE),
(cbind("I" = IR, "Acumulado" = CA,
"BaC" = SF)))),
c(R*input$n,sum(IR),
sum(CA),000))
})
})
我了解表格生成的计算,但是在 Shiny 中动态复制它的那一刻,我无法使其长度调整为周期数。
这是我想到该应用程序时的链接: https://github.com/pakinja/-Financial-Mathematics-in-R/blob/master/AmortizationFund.r#L40
【问题讨论】: