Error in max - min : non-numeric argument to binary operator

124 views
Skip to first unread message

Mithilesh Kumar

unread,
Jul 20, 2015, 5:08:23 AM7/20/15
to shiny-...@googlegroups.com
Hi all,

I am creating simple histogram in my Amazon ec2 rstudio. A double checked everything. 
I am plotting using result tables saved in .Rdata file. I have also checked the data types: All are numeric.
Still I'm getting above error my codes are:

ui.R
-----
# shiny plots on top_docs data

library(shiny)

shinyUI(fluidPage(
 # Header title
  titlePanel(title = h4("Top doctors plots - a histograms", align = "center")),

  # Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput(
selectInput("var", "1, Select the variables from top doc summary file", 
choices =c( "service_total" = 1, 
              "ben_total" = 2,
              "payment" = 3, 
              "charged" = 4, 
              "allowed" = 5, 
              "unique_services_per_patient" = 6, 
              "duplicates_per_service" = 7, 
              "services_per_patient" = 8), selected= 1 ),
        br(),
        sliderInput("bins", "2, Select the number of BINs for histogram", min = 5, max = 40, value=20),
        br(),
        radioButtons("color", "3, Select the color of histogram", choices =c("Green", "Red", "Yellow"), selected= "Green")
             
    )),

    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("myhist")
    )
  ))
)

-----------------------------------
server.R
----------
library(ggplot2)
library(shiny)
options(shiny.error=browser)

load("/home/mithilesh/data/top_docs.RData", envir=.GlobalEnv)
shinyServer(function(input, output) {

  output$myhist <- renderPlot({

    # generate var based on input$var from ui.R
    col <- as.numeric(input$var)
    hist(top_docs[,col], breaks = seq(0, max(top_docs[,col], l = input$bins+1), col=input$color, main="Histogram of Top docs", xlab=names(top_docs[col])))

  })

})

Mithilesh Kumar

unread,
Jul 20, 2015, 6:15:42 AM7/20/15
to shiny-...@googlegroups.com
You can take sample data as:
top_docs = data.frame( service_total = sample(1:100000, 40, replace=T), ben_total = sample(1:100000, 40, replace=T), payment = sample(1:100000, 40, replace=T), charged = sample(1:100000, 40, replace=T), allowed = sample(1:100000, 40, replace=T), unique_services_per_patient = runif(40, 1, 5.2), duplicates_per_service = runif(40, 1.1, 16.2), services_per_patient = runif(40, 1.3, 70) )

Kr Pawan pandit

unread,
Jul 20, 2015, 8:18:35 AM7/20/15
to shiny-...@googlegroups.com
Hi Mithilesh, 

I have modified your app and it is now working. I hope it would work in Amazon EC2. See the codes it will help you to identify the issue and I hope it is the thing that you want if not then please inform the detailed information that you require to implement. 

--------------------------------------------------------------
ui.R
---------------------
library(shiny)

shinyUI(fluidPage(
  # Header title
  titlePanel(title = h4("Top doctors plots - a histograms", align = "center")),
  
  # Sidebar with a slider input for number of bins
    sidebarPanel(
      
        selectInput("var", "1, Select the variables from top doc summary file", 
                    choices =c( "service_total" = 1, 
                                "ben_total" = 2,
                                "payment" = 3, 
                                "charged" = 4, 
                                "allowed" = 5, 
                                "unique_services_per_patient" = 6, 
                                "duplicates_per_service" = 7, 
                                "services_per_patient" = 8), selected= 1 ),
        br(),
        sliderInput("bins", "2, Select the number of BINs for histogram", min = 5, max = 40, value=20),
        br(),
        radioButtons("color", "3, Select the color of histogram", choices =c("Green", "Red", "Yellow"), selected= "Green")
        
      ),
    
    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("myhist")
    )
  )
)

---------------------------------------------------------------------------------------------

server.R
------------------------
library(ggplot2)
library(shiny)
options(shiny.error=browser)

#load("/home/mithilesh/data/top_docs.RData", envir=.GlobalEnv)
top_docs=data.frame( service_total = sample(1:100000, 40, replace=T), ben_total = sample(1:100000, 40, replace=T), 
                     payment = sample(1:100000, 40, replace=T), charged = sample(1:100000, 40, replace=T),
                     allowed = sample(1:100000, 40, replace=T), unique_services_per_patient = runif(40, 1, 5.2), 
                     duplicates_per_service = runif(40, 1.1, 16.2), services_per_patient = runif(40, 1.3, 70) )
shinyServer(function(input, output) {
  
  output$myhist <- renderPlot({
    
    # generate var based on input$var from ui.R
    col <- as.numeric(input$var)
    hist(top_docs[,col], breaks = seq(0, max(top_docs[,col]), length.out = input$bins+1), 
         col=input$color, main="Histogram of Top docs", xlab=names(top_docs[col]))
    
  })
  
})
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------- 

Mithilesh Kumar

unread,
Jul 20, 2015, 9:10:15 AM7/20/15
to shiny-...@googlegroups.com
Hi Pawan,

Your corrections working fine.

Thanks a ton :)
Reply all
Reply to author
Forward
0 new messages