R: In Shiny how do I fix no applicable method for 'xtable' applied to an object of class “reactive”

旧街凉风 提交于 2021-01-27 16:58:29

问题


I'm getting this error:

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

UI.R

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')
  )
))

Server.R

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
    })
  }
)

回答1:


reactive returns a function. To call the reactive function you would use:

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


来源:https://stackoverflow.com/questions/27682781/r-in-shiny-how-do-i-fix-no-applicable-method-for-xtable-applied-to-an-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!