【发布时间】:2021-10-24 22:04:48
【问题描述】:
我不久前才开始学习 Shiny。我想把y赋值给(y1+y2+y3+y4)/4,在其他地方调用这个赋值y。 p>
起初我尝试了简单的定义
y=(input$y1+input$y2+input$y3+input$y4)/4,但它不起作用。我也尝试了很多其他方法,但都没有奏效。
因为我会在后面的计算中多次使用y(比如计算方差),但是每次使用(input$y1+input$y2+input$y3+input$y4)/4都会很臃肿(yi, 我可能会超过20)
我的部分代码如下,
shinyUI(fluidPage(
numericInput("y1", "y1:", sample(1:200,1), min = 1, max = 200)),
numericInput("y2", "y2:", sample(1:200,1), min = 1, max = 200)),
numericInput("y3", "y3:", sample(1:200,1), min = 1, max = 200)),
numericInput("y4", "y4:", sample(1:200,1), min = 1, max = 200))
))
shinyServer(function(input, output,session) {
output$y <- renderText({(input$y1+input$y2+input$y3+input$y4)/4})
})
不知道有没有合适的解决方案。
【问题讨论】:
标签: r shiny shiny-server shinyapps shiny-reactivity