总结使用dplyr和Shiny [英] Summarize using dplyr and shiny

查看:151
本文介绍了总结使用dplyr和Shiny的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个应用设置,可以让用户输入他们想要绘制和可视化的变量。我在尝试将闪亮的输入变量传递给摘要时遇到问题。

I currently have an app setup where it lets the user input which variable they want to plot and visualize. I am running into an issue when I am trying to pass off the shiny input variable into summarize.

testData <- plotData %>% 
        summarize(means=mean(input$selectedMetric, na.rm=TRUE)) %>%
        summarize(sd=sd(input$selectedMetric, na.rm=TRUE))

我得到的错误如下:

Warning in mean.default(input$selectedMetric, na.rm = TRUE) :
argument is not numeric or logical: returning NA

如何我是否应该进行设置,使其采用用户决定的所选列的均值和标准差?

How am I supposed to set it up so that it takes the mean and standard deviation of whatever selected column the user decides?

推荐答案

此处可能会出错:


  • 使用 input $ selectedMetric

您不正确地使用了反应堆。您应该在最后使用()访问反应式,因为它们是返回某些内容的函数。

You improperly using reactives. You should access the reactives by using () at the end as they are functions that return something.

在我下面,假设您的 plotData 变量不是反应型变量,而是声明的对象

Below Im assuming that your plotData variable isn't a reactive and its a declared object

testData <- reactive({
  if(is.null(input$selectedMetric)){
    return()
  }
  plotData %>% 
    summarize(means=mean(input$selectedMetric, na.rm=TRUE)) %>%
    summarize(sd=sd(input$selectedMetric, na.rm=TRUE))
})

testData()

您可以这样访问摘要: testData()

You can access the summary, like so: testData()

这篇关于总结使用dplyr和Shiny的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆