【问题标题】:R: In Shiny how do I fix no applicable method for 'xtable' applied to an object of class "reactive"R:在Shiny中,我如何修复没有适用于“反应性”类对象的“xtable”方法
【发布时间】:2014-12-29 02:42:03
【问题描述】:

我收到此错误:

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

服务器.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
    })
  }
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    reactive 返回一个函数。要调用您将使用的反应函数:

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

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 2014-09-06
      • 2017-12-30
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 2022-09-24
      相关资源
      最近更新 更多