R-闪亮矩阵中二进制运算符的非数字参数

弗朗西斯·瑞安(Francis Ryan)

我是r的新手(并且通常是编程人员),我们被要求使用r发光的Web应用程序,计划是从不同的输入文件制作一个矩阵运算计算器,(第一个.cvs文件包含矩阵1,第二个.cvs文件包含矩阵2),但始终出现错误

 Listening on http://127.0.0.1:3420
 Warning: Error in FUN: non-numeric argument to binary operator
 99: eval
 98: eval
 97: Ops.data.frame
 96: renderTable [C:/Users/Acer/Desktop/FirstWebApp/app (1).R#45]
 95: func
 82: origRenderFunc
 81: output$oput
  1: runApp

这是我的UI

     ui <- fluidPage(
  titlePanel("Multiple file uploads"),
  sidebarLayout(
    sidebarPanel(
     fileInput("file1",
               label="Upload CSVs here"),
     fileInput("file2", "upload file here"),
     selectInput("ops", "Select Operation",
                 choices = c("addition","subtraction","multiplication","division"))
     
  ),
  mainPanel(
     tableOutput("input_file"),
     tableOutput("input_file2"),
     tableOutput("oput")

server看起来像这样

server <- function(input, output) {
output$input_file <- renderTable({
  file_to_read =  input$file1
  if (is.null(file_to_read)) {
    return()
 }
  read.table(file_to_read$datapath, sep = ',', header = FALSE)
})

output$input_file2 <- renderTable({
  file_to_read =  input$file2
  if (is.null(file_to_read)) {
    return()
  }
  read.table(file_to_read$datapath, sep = ',', header = FALSE)
})
output$oput <- renderTable({
switch(input$ops,
       "addtion" = input$file1 + input$file2,
       "subtraction" = input$file1 - input$file2,
       "multiplication" = input$file1 * input$file2,
       "division" = input$file1 / input$file2)
})
}

如何解决此问题,如果此错误已解决,程序将运行吗?

Ben

您的input$file1input$file2将包含文件名和路径,但不包含数据本身(它与一起在其他位置读取read.table)。因此,除非您向矩阵运算提供数据,否则矩阵运算将不起作用。

我建议考虑使用reactive表达式从csv文件访问数据。尽管许多教程将演示您所拥有的内容(直接在中读取数据output renderTable,但这对于在其他上下文中使用数据可能不太灵活。

在下面,反应式表达式data1将读取存储在中的csv文件input$file1然后,要访问数据,只需将其称为data1()这既包括output$table1(仅显示表中的数据),也包括output$table3显示矩阵运算的结果。请注意,在下面的示例中,tableOutput为了澄清起见,我将其重命名为“ table1”,“ table2”和“ table3”。

我希望这可以澄清问题-让我知道任何问题。

library(shiny)

ui <- fluidPage(
  titlePanel("Multiple file uploads"),
  sidebarLayout(
    sidebarPanel(
      fileInput("file1", label = "Upload CSV 1"),
      fileInput("file2", label = "Upload CSV 2"),
      selectInput("ops", "Select Operation",
                  choices = c("addition", "subtraction", "multiplication", "division"))
    ),
    mainPanel(
      tableOutput("table1"),
      tableOutput("table2"),
      tableOutput("table3")
    )
  )
)

server <- function(input, output) {
  
  data1 <- reactive({
    file_to_read =  input$file1
    if (is.null(file_to_read)) {
      return()
    }
    read.table(file_to_read$datapath, sep = ',', header = FALSE)
  })
  
  output$table1 <- renderTable({
    data1()
  })
  
  data2 <- reactive({
    file_to_read =  input$file2
    if (is.null(file_to_read)) {
      return()
    }
    read.table(file_to_read$datapath, sep = ',', header = FALSE)
  })
  
  output$table2 <- renderTable({
    data2()
  })
  
  output$table3 <- renderTable({
    switch(input$ops,
           "addition" = data1() + data2(),
           "subtraction" = data1() - data2(),
           "multiplication" = data1() * data2(),
           "division" = data1() / data2())
  })
}

shinyApp(ui, server)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类常见问题

当两个元素都是数字时,二进制运算符的非数字参数

来自分类Dev

二进制运算符的非数字参数

来自分类Dev

R ff程序包创建新列时出现错误“二进制运算符的非数字参数”

来自分类Dev

R使用diff:二进制运算符错误的非数字参数

来自分类Dev

二进制运算符aes函数的非数字参数

来自分类Dev

getReturns中的“二进制运算符的非数字参数”错误

来自分类Dev

适用于二进制运算符错误的非数字参数

来自分类Dev

如果ggplot中的Statement在R中导致错误,则为二进制运算符的非数字参数

来自分类Dev

如何向数据框添加行并避免“二进制运算符的非数字参数”

来自分类Dev

R闪亮的“二进制运算符的非数字参数”错误

来自分类Dev

R caret:使用qrf进行训练时的“二进制运算符的非数字参数”

来自分类Dev

ompr MILPModel:二进制运算符的非数字参数

来自分类Dev

当两个元素都是数字时,二进制运算符的非数字参数

来自分类Dev

R-闪亮的错误“二进制运算符的非数字参数”

来自分类Dev

为什么libstdc ++在迭代器上对二进制运算符同时实现<L,R>和<LR>重载?

来自分类Dev

drc中的错误“ parmVec [3]中的错误-respl:二进制运算符的非数字参数”

来自分类Dev

R中二进制运算的非数字参数错误,需要说明

来自分类Dev

如何在R中不覆盖而使用二进制运算符

来自分类Dev

Python中二进制数的二进制运算符

来自分类Dev

添加边缘时出现R iGraph错误“二进制运算符的非数字参数”

来自分类Dev

错误的原因是什么:R中二进制运算符的非数字参数

来自分类Dev

R-闪亮包-二进制运算符的非数字参数

来自分类Dev

二进制运算符错误的非数字参数仅在apply之内

来自分类Dev

-0.01 * height中的错误:二进制运算符的非数字参数

来自分类Dev

如果ggplot中的Statement在R中导致错误,则为二进制运算符的非数字参数

来自分类Dev

R中的函数错误,二进制运算符的非数字参数

来自分类Dev

R中二元运算符的非数字参数

来自分类Dev

如何计算r中二进制变量之间的相关矩阵?

来自分类Dev

CSV 文件:-0.01 * 高度中的错误:R 中二元运算符的非数字参数

Related 相关文章

  1. 1

    当两个元素都是数字时,二进制运算符的非数字参数

  2. 2

    二进制运算符的非数字参数

  3. 3

    R ff程序包创建新列时出现错误“二进制运算符的非数字参数”

  4. 4

    R使用diff:二进制运算符错误的非数字参数

  5. 5

    二进制运算符aes函数的非数字参数

  6. 6

    getReturns中的“二进制运算符的非数字参数”错误

  7. 7

    适用于二进制运算符错误的非数字参数

  8. 8

    如果ggplot中的Statement在R中导致错误,则为二进制运算符的非数字参数

  9. 9

    如何向数据框添加行并避免“二进制运算符的非数字参数”

  10. 10

    R闪亮的“二进制运算符的非数字参数”错误

  11. 11

    R caret:使用qrf进行训练时的“二进制运算符的非数字参数”

  12. 12

    ompr MILPModel:二进制运算符的非数字参数

  13. 13

    当两个元素都是数字时,二进制运算符的非数字参数

  14. 14

    R-闪亮的错误“二进制运算符的非数字参数”

  15. 15

    为什么libstdc ++在迭代器上对二进制运算符同时实现<L,R>和<LR>重载?

  16. 16

    drc中的错误“ parmVec [3]中的错误-respl:二进制运算符的非数字参数”

  17. 17

    R中二进制运算的非数字参数错误,需要说明

  18. 18

    如何在R中不覆盖而使用二进制运算符

  19. 19

    Python中二进制数的二进制运算符

  20. 20

    添加边缘时出现R iGraph错误“二进制运算符的非数字参数”

  21. 21

    错误的原因是什么:R中二进制运算符的非数字参数

  22. 22

    R-闪亮包-二进制运算符的非数字参数

  23. 23

    二进制运算符错误的非数字参数仅在apply之内

  24. 24

    -0.01 * height中的错误:二进制运算符的非数字参数

  25. 25

    如果ggplot中的Statement在R中导致错误,则为二进制运算符的非数字参数

  26. 26

    R中的函数错误,二进制运算符的非数字参数

  27. 27

    R中二元运算符的非数字参数

  28. 28

    如何计算r中二进制变量之间的相关矩阵?

  29. 29

    CSV 文件:-0.01 * 高度中的错误:R 中二元运算符的非数字参数

热门标签

归档