闪亮服务器中的一个输出将在另一个输出中使用

问题描述 投票:1回答:2

我有一个问题是一个输出是否可用于另一个输出?我希望使用输出$ mysum的结果在我的输出$ condition中使用

 output$condition= renderText({
        if (output$mysum <20) {
          print("The sum of the time is less than 20")

        }
      })

      output$mysum <- renderText({

      x=input$number
      x=x+1
        }
      })
r shiny shinydashboard
2个回答
1
投票

使用reactive expression,其值可以在任何output中使用。例如:

sumone <- reactive({
  input$number+1
})
output$condition <- renderText({
   if (sumone() < 20) {
     print("The sum of the time is less than 20")
   }
})
output$mysum <- renderText({
   sumone()
})

0
投票

如果让我说从2015年输入$ year获得一个值速度,那么我想将此值用作输出$ mysum的条件因子。它可以用反应来完成吗?

output$condition <- renderText({
 if(input$year==2015){
 speed=as.numeric(sqldf("select ave_speed from newdataset where [month]=12 
 AND [day]=30 AND [regionid]=16"))
        }

   }
})
output$mysum <- renderText({
    if(speed<30){
  month=as.numeric(sqldf("select month from newdataset where [month]=12 AND 
  [day]=30 AND [regionid]=16"))
     }
})
© www.soinside.com 2019 - 2024. All rights reserved.