简体   繁体   English

尝试使用R中的闪亮应用程序创建一个未来值计算器并得到错误:“ cat”无法处理参数1(类型“ closure”)

[英]Trying to create a future value calculator with shiny app in R and get error: argument 1 (type 'closure') cannot be handled by 'cat'

This is the code I have on my server file: 这是我服务器文件上的代码:

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)

})

Code for main panel on UI File: 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")
)

Everything works except for the last part where I'm performing the calculations for future value. 一切正常,除了最后一部分,我在其中进行终值的计算。 Would anyone be able to tell me what I'm doing wrong? 谁能告诉我我做错了什么?

Hi reactivs are functions not variables 喜重新激活功能不是变量

output$fv <- renderText(futureValue() ) 

and change the reactive function like this 并这样改变反应功能

futureValue <- reactive({ 
  principal <- input$Slider1     
  numberOfPeriods <- input$numeric1 
 rate <- input$numric2 
 fvalue <-principal*(((1+rate)^numberOfPeriods-1)/rate) 
 return(fvalue) })

should solve it. 应该解决它。

Hope this helps! 希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 闪亮的应用程序失败,“参数1(类型&#39;封闭&#39;)无法由&#39;猫&#39;处理” - 这是什么意思? - Shiny app fails with “argument 1 (type 'closure') cannot be handled by 'cat'” - what does this mean? R - 闪亮| cat中的错误(列表(...),文件,sep,fill,labels,append):&#39;cat&#39;无法处理参数1(类型&#39;list&#39;) - R - Shiny | Error in cat(list(…), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' 警告:cat 中的错误:R shiny webtool 中的 'cat' [No stack trace available] 无法处理参数 1(类型 'list') - Warning: Error in cat: argument 1 (type 'list') cannot be handled by 'cat' [No stack trace available] in R shiny webtool 对档案进行闪亮的反应式扫描,然后将其写入()以下载,在cat()-&gt;参数类型“关闭”中未处理失败 - Shiny reactive scan of archive, then write() it to download, fails in cat() -> argument type “closure” not handled 问题打印回归树,“cat(x, ..., sep = sep) 中的错误:参数 1(类型‘list’)无法由‘cat’处理” - Problem Printing Regression Tree, "Error in cat(x, ..., sep = sep) : argument 1 (type 'list') cannot be handled by 'cat'" R闪亮错误:无法强制类型&#39;封闭&#39;到&#39;double&#39;类型的向量 - R shiny error: Cannot coerce type 'closure' to vector of type 'double' 错误:无法将“闭包”类型强制转换为“字符”类型的向量 - Shiny R - Error: cannot coerce type 'closure' to vector of type 'character' - Shiny R R Shiny中类型为“ closure”的无效“ envir”参数 - invalid 'envir' argument of type 'closure' in R shiny &#39;闭合&#39;类型的对象不是子集:R闪亮的应用程序 - object of type 'closure' is not subsettable: R shiny App $ 中的错误:object 类型“关闭”不是子集 shiny R - Error in $: object of type 'closure' is not subsettable shiny R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM