ujjwal tyagi
ujjwal tyagi

Reputation: 493

$ operator is invalid for atomic vectors in shiny R

There is a function in psych package called 'alpha' which gives out various statistics. I want a specific column from the output so I use a code. This code works perfectly in console but it doesn't work when I try to use it in shiny.

library(shiny)
library(mirt)#This contains a dataset called deAyala
library(psych)#This has the alpha() function

server<- shinyServer(
    
    function(input, output) {
        
        output$data <- renderUI({
            
            alpha(deAyala,warnings=FALSE)$item.stats$raw.r #Warning disables the warnings 
            
            
            
        })
        
        
    }
)


ui<- shinyUI(fluidPage(
    titlePanel(title = h4("Output", align="center")),
    sidebarLayout(
        sidebarPanel(
        ),
        
        mainPanel(
            uiOutput("data"),
            
        )
        
    )
    
))


shinyApp(ui = ui, server = server)

Upvotes: 1

Views: 134

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

You can use renderTable or renderText to display the output instead of renderUI.

library(shiny)

server<- shinyServer(
  function(input, output) {
    output$data <- renderTable({
      alpha(deAyala,warnings=FALSE)$item.stats$raw.r
    })
  }
)

ui<- shinyUI(fluidPage(
  titlePanel(title = h4("Output", align="center")),
  sidebarLayout(
    sidebarPanel(
    ),
    mainPanel(
      tableOutput("data"),
    )
  )
))

shinyApp(ui = ui, server = server)

enter image description here

Upvotes: 1

Related Questions