2017-04-22 48 views
-1

我試圖從一個反應對象獲得像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

有人嗎?

+0

你能告訴潛在的輸入是什麼樣子?這可能取決於'+'符號作爲'searchArtist'的輸入。 – timfaber

+0

輸入由:textInput(「artist」,「Artist/Band」, value =「The Beatles」,width = NULL,placeholder = NULL) –

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