我收到这个错误:
Error in UseMethod("xtable") :
no applicable method for 'xtable' applied to an object of class "reactive"
Run Code Online (Sandbox Code Playgroud)
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')
)
))
Run Code Online (Sandbox Code Playgroud)
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
})
}
)
Run Code Online (Sandbox Code Playgroud)
reactive返回一个函数.要调用反应函数,您将使用:
output$searchResult <- renderTable({
searchResult()
})
Run Code Online (Sandbox Code Playgroud)