从反应对象中获取data.frame闪亮
问题描述:
我试图从一个反应对象获得像data.frame一样的结果,但没有成功。目的是这样的:在这种情况下从反应对象中获取data.frame闪亮
textInput("artist", "Artist/Band", value = "The Beatles", width = NULL, placeholder = NULL)
artist <- reactive({searchArtist(input$artist)})
错误消息,R闪亮的错误:类型的对象 '关闭' 不subsettable
其中,例如,我们有:
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
。
有人吗?
答
见注释:
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)
你能告诉潜在的输入是什么样子?这可能取决于'+'符号作为'searchArtist'的输入。 – timfaber
输入由:textInput(“artist”,“Artist/Band”, value =“The Beatles”,width = NULL,placeholder = NULL) –
当我输入“披头士乐队”,“披头士乐队”,“芭蕾舞团”时,它实际上工作正常。我认为这不是问题。 –