Tarak
Tarak

Reputation: 1075

Shiny - Reactive and observe event confusion

I have a text input which is "inputProductID" and action button which is "actionGetDetails"

After entering a specific product ID say 12345 in the text input, I click on the action button. On clicking the action button I wish to call a function which takes in product ID as input argument and give a dataframe as output. The dataframe has single row and various columns like ProductName, productDescription etc. I wish to take the value of ProductName from the dataframe and display/render to the output text field on that action button click. here is what I tried:

            shinyServer(function(input, output,session) {

              # Here actionGetDetails is the action button
              # inputProductID is the input text field
              ntext <- eventReactive(input$actionGetDetails, {
                 getProductDetails(input$inputProductID)
                 # This function returns a dataframe have a field ProductName
              })

              # Here  output$textvar is the 
               output$textvar <- renderText({
                 ntext$ProductName
                })

I get an error on the app:object of type 'closure' is not subsettable.

I tried using the combination of observeEvent() and reactivevalues Anyhelp in solving this would be appreciated.

Upvotes: 0

Views: 283

Answers (1)

HubertL
HubertL

Reputation: 19544

ntext is a function returning a data.frame, so you have to use it like this :

output$textvar <- renderText({
             ntext()$ProductName
            })

Upvotes: 1

Related Questions