警告:<= 中的错误:比较 (4) 仅适用于原子和列表类型

Warning: Error in <=: comparison (4) is possible only for atomic and list types

我有这个示例应用程序: 用户应该选择一些行,从中生成一个随机值,输出是一个值图。

我想将输入与行号进行比较,但出现此错误:

Warning: Error in <=: comparison (4) is possible only for atomic and list types
  48: ifelse


library(shiny)


ui <- fluidPage(

    
    titlePanel("Random numbers"),

  
    sidebarLayout(
        sidebarPanel(
            sliderInput("row",
                        "Row number:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

     
        mainPanel(
           plotOutput("rowPlot")
        )
    )
)


server <- function(input, output) {

  
  rowTable <- data.frame(rowNumber = as.integer(), value = as.integer())
  rowTable[1:50, ] <- NA
  rowTable[["rowNumber"]] <- 1:50
  rowTable[["value"]] <- ifelse(rowTable[["rowNumber"]] <= reactive({input$row}), 0, rnorm(50))
  
  
    output$rowPlot <- renderPlot({
       
        plot(rowTable[["rowNumber"]], rowTable[["value"]])
    })
}


shinyApp(ui = ui, server = server)

reactive

中创建 data.frame
server <- function(input, output) {
  
  
  
  dat <- reactive({
    
    rowTable <- data.frame(rowNumber = as.integer(), value = as.integer())
    rowTable[1:50, ] <- NA
    rowTable[["rowNumber"]] <- 1:50
    
    rowTable[["value"]] <- ifelse(rowTable[["rowNumber"]] <= as.numeric(input$row), 0, rnorm(50))
    rowTable
   })
  
  
  output$rowPlot <- renderPlot({
    tmp <- dat()
    plot(tmp[["rowNumber"]], tmp[["value"]], xlab = "rowNumber", ylab = "value")
  })
  })
}

-测试

shinyApp(ui = ui, server = server)

-输出