【问题标题】:Subtract columns in dataframe Shiny减去数据框中的列 Shiny
【发布时间】:2020-06-03 19:34:06
【问题描述】:

我有一个数据框。我想选择要减去的列并绘制结果列值。当我运行应用程序时,我收到以下错误:

二元运算符的非数字参数

我理解错误的含义,但我正在努力找出答案。有人能把我从痛苦中解救出来吗?

下面是代码:

library(shiny)
library(shinyWidgets)
library(ggplot2)
library(tidyverse)

df<-data.frame('date'=c('2020-01-01','2020-01-02','2020-01-03'),
               'a'=c(1,3,8),'b'=c(2,4,9),'c'=c(0,1,7))

ui <- fluidPage(
  fluidRow(
      column(width=4,pickerInput('input1','Select 1',names(df[,-1]))),
      column(width=4,pickerInput('input2','Select 2',names(df[,-1]))),
      plotOutput('plot')

))

server <- function(input, output, session) {

    dt<-reactive({df%>%mutate(diff=input$input1-input$input2)})

    output$plot<-renderPlot({ggplot(dt(),aes(date,diff))+geom_point()})

}

shinyApp(ui, server)```

【问题讨论】:

    标签: r dplyr shiny


    【解决方案1】:

    您可以将!!as.name 一起使用:

    mutate( diff = !!as.name(input$input1) - !!as.name(input$input2) )
    

    【讨论】:

      猜你喜欢
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多