2015-07-20 27 views
0

我想創建一個簡單的閃亮的應用程序,繪製運行在亞馬遜ec2 rstudio內的直方圖爲我的結果數據存儲爲.RData文件。我已經加倍檢查了一切。它看起來很好。 我也檢查了數據類型:全部是數字。R閃亮:錯誤在最大 - 最小:二進制運算符的非數字參數

我的代碼:

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("/******/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]))) 

    }) 

}) 
` 
+0

無法重現示例。你應該把一些數據樣本,而不是'load(「。RData」)'。無論如何,可能錯誤發生在'seq(0,max(top_docs [,col],l = input $ bins + 1)'where')「缺少max()'函數 –

+0

嗨,我糾正了缺失的」) 「操作員,我仍然得到相同的錯誤。 –

+0

對於樣品數據: 可以採取 'top_docs = data.frame( \t service_total =樣品(1:100000,40,替換= T), ben_total =樣品(1:100000,40,替換= T), (1:100000,40,取代= T), \t收費=樣本(1:100000,40,替換= T), \t允許=樣本(1:100000,40,替換= T) , \t unique_services_per_patient = runif(40,1,5.2), \t duplicates_per_service = runif(40,1.1,16.2), \t services_per_patient = runif(40,1.3,70) )' –

回答

1

發現它...所有的sidebarPanel內容是sliderInput函數內部的給出錯誤

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

# shiny plots on top_docs data 
library(shiny) 
ui <- 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(   < ------------- HERE 
     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") 

     #)   < ------------- HERE 
    ), 

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

server <- 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])) 

    }) 

}) 

shinyApp(ui, server) 
+0

感謝ton @Andriy Tkachenko,現在工作正常! –

+0

很高興喲幫助你!您可以將答案標記爲解決方案,因此問題不會顯示爲未解決 –

相關問題