我试图从反应对象中获取类似data.frame的结果,但没有成功。对象类似于:
textInput("artist", "Artist/Band", value = "The Beatles", width = NULL, placeholder = NULL)
artist <- reactive({searchArtist(input$artist)})
在这种情况下出现错误信息:R shiny ERROR:类型为&#39;关闭的对象&#39;不是子集表格
例如,我们有:
artist <- searchArtist("Regina+spektor")
str(artist)
'data.frame': 1 obs. of 6 variables:
$ id : chr "3z6Gk257P9jNcZbBXJNX5i"
$ name : chr "Regina Spektor"
$ popularity: int 65
$ genres :List of 1
..$ : chr "acoustic pop" "anti-folk" "folk-pop" "indie folk" ...
$ type : chr "artist"
$ followers : num 691496
我还有这段代码,works
:
output$table <- renderDataTable({
inFile <- searchArtist(input$artist)
if (is.null(inFile))
inFile[2:6]
})
dataTableOutput("table")
函数searchArtist
来自包Rspotify
。
任何?
答案 0 :(得分:1)
见评论:
library("Rspotify")
library("shiny")
ui=shinyUI(fluidPage(
sidebarPanel(
textInput("artist", "Artist/Band", value = "The Beatles", width = NULL, placeholder = NULL)
),
mainPanel(
textOutput("text")
)
))
server=shinyServer(function(input, output) {
artist <- reactive({
searchArtist(input$artist)
})
output$text = renderText({
data <- artist()
print(data$id)
})
})
shinyApp(ui=ui,server=server)