这是我服务器文件中的代码:
shinyServer(function(input, output) {
output$P = renderText(input$Slider1)
output$n = renderText(input$numeric1)
output$r = renderText(input$numeric2/100)
futureValue <- reactive({
principal <- output$P
numberOfPeriods <- output$n
rate <- output$r
fvalue <- principal*(((1+rate)^numberOfPeriods-1)/rate)
return(fvalue)
})
output$fv <- renderText(futureValue)
})
UI文件主面板代码:
sidebarPanel(
h4("Select Monthly Investment Amount:"),
sliderInput("Slider1","Select Monthly Investment Amount:", 100, 1000,
100),
numericInput("numeric1", "Select Number of Payments:", value = 12, min
= 6, max = 60, step = 1),
numericInput("numeric2", "Select Interest Rate Percentage:", value =
3.0, min = 0.1, max = 5.0, step = 0.1)
mainPanel
(
h4("Monthly Investment Amount:"),
textOutput("P"),
h4("Number of Periods:"),
textOutput("n"),
h4("Interest Rate:"),
textOutput("r"),
h4("Under the given circumstances, the future value of your
investment is:"),
textOutput("fv")
)
除了最后一部分,我正在为未来的价值进行计算,一切都有效。谁能告诉我我做错了什么?
答案 0 :(得分:0)
Hi reactivs是函数而不是变量
output$fv <- renderText(futureValue() )
并像这样改变反应函数
futureValue <- reactive({
principal <- input$Slider1
numberOfPeriods <- input$numeric1
rate <- input$numric2
fvalue <-principal*(((1+rate)^numberOfPeriods-1)/rate)
return(fvalue) })
应该解决它。
希望这有帮助!