我收到此错误:

Error in UseMethod("xtable") :
  no applicable method for 'xtable' applied to an object of class "reactive"

用户界面
library(shiny)
shinyUI(pageWithSidebar(
  headerPanel("Test App"),
  sidebarPanel(
    textInput(inputId="text1",
              label = "Enter Keywords"),
    actionButton("goButton", label = "Go!", icon = "search")
  ),
  mainPanel(
    p('Your search:'),
    textOutput('text1'),
    p(''),
    textOutput('text3'),
    p('Search Results'),
    tableOutput('searchResult')
  )
))

服务器端
library(shiny)

data <- read.csv("./data/data.csv", quote = "")

shinyServer(
  function(input, output) {
    searchResult<- reactive({
      subset(asos, grepl(input$text1, asos$Title))
    })

    output$text1 <- renderText({input$text1})
    output$text3 <- renderText({
      if (input$goButton == 0) "Get your search on!"
      else if (input$goButton == 1) "Computing... here's what I found!"
      else "OK, I updated the results!"
    })
    output$searchResult <- renderTable({
      searchResult
    })
  }
)

最佳答案

reactive 返回一个函数。要调用 react 函数,您将使用:

output$searchResult <- renderTable({
  searchResult()
})

关于R:在 Shiny 中,如何修复应用于 'xtable' 类的对象的 "reactive"没有适用的方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27682781/

10-12 23:29