2016-08-30 23 views
-1

編集 アプリが今起動し、私はまだ1つの警告があります。光沢のあるアプリのヒストグラムエラー

警告:+でエラーが発生しました:(最初の最も内側)単項演算子 スタックトレースに無効な引数: 76: renderPlot [C:\ Users \ユーザーjcopelan書類が契約/ app.R番号を\ \ 107] 68:出力$ distPlot 1:runApp

私はそれがggplotするコールとは何かを持っていると信じていますが、私ができます」問題が何であるかを正確に突き止める。また、データセット全体からランダム化された100の観測データを追加しました。


私はRで、selectInputボックスから選択を受けて、これに基づいてデータフレームをサブセット化する光沢のあるアプリケーションを作成しています。選択肢はdoubleタイプの列になり、ggplot2を使用してヒストグラムとしてプロットされます。すべてがうまくBase Rで実行されていますが、セクションをサーバーセクションとuiセクションに解析した後、「x」はhist内の数値でなければなりません。どんな提案も感謝しています!

library(shiny) 
library(ggplot2) 

#Read in the service contract data set (all zero values from ECC and missing IBASE deleted out) 


NotUnique = read.table("C:\\Users\\jcopelan\\Documents\\InService.txt", header = F, sep = ",") 

#Name the df columns 
names(NotUnique) = c("Contract_Number", "Contract_Transaction","Region", "IBaseModel_Number", "IBase_Agilent_Model","Start_Date", "IBase_Parent", "End_Date", "Sold_To", "Ship_To", "Sell_Date", "Total_Net", "List_Price", "NotSure", "True_Net", "GrossVal") 

#Make a new dataframe that consists of only the first entry in the contract price, this way I can make histograms for regions and such 
InService = NotUnique[!duplicated(NotUnique$Contract_Number, decreasing = T),] 

InService$Start_Date = as.Date(as.character(InService$Start_Date)) 
InService$End_Date = as.Date(as.character(InService$End_Date)) 


# Define UI for application that draws a histogram 
ui <- shinyUI(fluidPage(

# Application title 
titlePanel("Contract Summary Application"), 

# Sidebar with a slider input for number of bins 
sidebarLayout(
    sidebarPanel(
    selectInput('Region', 
       'Region', 
       choices = c("Americas", "EMEA", "Greater China", "India", 
          "Japan", "SAPK","WorldWide"), selected = "Americas") 
), 

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

# Define server logic required to draw a histogram 
server <- shinyServer(function(input, output) { 

NetVal = reactive({as.data.frame(subset(InService, Region %in% input$Region)$True_Net)}) 
#Make the histogram plot with ggplot2 
breaks = reactive({seq(min(NetVal()), max(Netval()), 
      length.out = round(max(NetVal()), digits = 4)/500)}) 

hist = reactive({hist(NetVal(),breaks(), plot=FALSE)}) 
binmax = reactive({max(hist()$counts)}) 



output$distPlot <- renderPlot({ 
    regplot = ggplot(NetVal(), aes(NetVal, color = "Blue")) 
    + geom_histogram(binwidth = 500) 
    + ylim(c(0,binmax())) 
    + xlim(c(min(NetVal()),quantile(NetVal(),.95))) 
    + xlab("Amount Spent ($)") 
    + ylab("Frequency") 
    + fte_theme() 

print(regplot) 
}) 
}) 

# Run the application 
shinyApp(ui = ui, server = server) 

は、ここで私はあなたの+兆しはなく、前の行の末尾の新しい行にあるため、「単項演算子」のエラーがあると信じていたランダム化データセット

structure(list(Region = structure(c(7L, 3L, 3L, 6L, 2L, 2L, 2L, 
3L, 3L, 7L, 1L, 2L, 1L, 6L, 5L, 3L, 7L, 3L, 2L, 1L, 3L, 7L, 7L, 
3L, 2L, 3L, 3L, 3L, 7L, 3L, 3L, 2L, 3L, 4L, 3L, 3L, 4L, 2L, 3L, 
3L, 2L, 3L, 2L, 3L, 2L, 3L, 4L, 3L, 3L, 2L, 6L, 3L, 5L, 3L, 3L, 
2L, 7L, 3L, 5L, 3L, 4L, 7L, 7L, 3L, 3L, 3L, 5L, 3L, 3L, 7L, 7L, 
2L, 2L, 5L, 2L, 3L, 3L, 3L, 3L, 3L, 7L, 3L, 3L, 3L, 5L, 2L, 2L, 
3L, 2L, 3L, 3L, 3L, 3L, 5L, 7L, 1L, 5L, 3L, 7L, 2L), .Label = c("", 
"Americas", "EMEA", "Greater China", "India", "Japan", "SAPK" 
), class = "factor"), True_Net = c(10522.2, 3607.2, 33043.92, 
550800, 48242.37, 140040, 216607.2, 4278, 11880, 3737.48, 9830.4, 
215355, 7380000, 225000, 190440, 6825.6, 2000.05, 42982.21, 3528429.41, 
6456000, 16174.08, 205824, 103998, 2774.4, 14833.44, 42210, 3824.64, 
24942.34, 63036.23, 1392, 5522.4, 50443.2, 23086.8, 124698.23, 
140908.8, 66288, 81667.02, 636, 1968, 3861.36, 3732, 80000, 21808.8, 
2101.56, 40884, 103104, 94070.03, 24336, 2494.8, 52176, 719100, 
1015.2, 48917.74, 2713.2, 27907.2, 19668, 15614.4, 5809.44, 300192, 
67564.8, 18423, 6038.4, 34224, 1170, 1630.8, 26523.31, 1390000, 
62763.2, 25671.09, 80592, 6134.69, 235176, 57648, 205999.78, 
50136, 2130, 16976.28, 0, 10127.4, 4483.51, 2688, 1644157.2, 
3336, 9930.12, 37378.8, 197143.2, 19668, 14664, 45651.6, 576, 
10519.13, 5603.78, 5011.2, 333024, 46920, 1782000, 147108, 18048, 
8345.88, 4580.06)), .Names = c("Region", "True_Net"), row.names = c(139252L, 
168993L, 50887L, 147555L, 42219L, 137207L, 39332L, 164003L, 129109L, 
76248L, 142612L, 183452L, 146662L, 96736L, 18778L, 27846L, 190910L, 
57055L, 121244L, 124567L, 168122L, 203483L, 79170L, 37398L, 38729L, 
132515L, 98739L, 129955L, 87175L, 106204L, 10986L, 17875L, 168417L, 
206082L, 104991L, 1090L, 141201L, 157185L, 96915L, 196929L, 28880L, 
211286L, 69145L, 70201L, 215507L, 57974L, 151559L, 113300L, 146977L, 
108231L, 125906L, 210328L, 189968L, 125125L, 78831L, 66537L, 
77616L, 47462L, 14840L, 175840L, 173340L, 66249L, 121586L, 177159L, 
40958L, 44729L, 143400L, 19238L, 150885L, 3012L, 196802L, 149237L, 
115877L, 136052L, 196532L, 73278L, 72437L, 126332L, 26803L, 187446L, 
186575L, 37180L, 192443L, 133701L, 203954L, 186105L, 47635L, 
155246L, 25619L, 167488L, 79686L, 44698L, 29360L, 14347L, 193909L, 
139130L, 185265L, 147108L, 157757L, 81261L), class = "data.frame") 
+2

「NetVal」ではなく「NetVal()」を使用する必要があります。 [参照してください。](http://shiny.rstudio.com/tutorial/lesson6/) – Axeman

+0

コメントをお寄せいただきありがとうございます。そのエラーを過ぎて私にこの1つを渡します:Warning:.getReactiveEnvironment()のエラー$ currentContext:アクティブなリアクティブ・コンテキストなしでは操作は許可されません。スタックトレース(最も内側にあるもの): 44:.getReactiveEnvironment()$ currentContext 43:依存関係$ register 42:NetVal 41 :seq 40:サーバー[C:\ Users \ jcopelan \ Documents \ Contracts/app.R#97] 1:runApp –

+0

あなたのコードを実行しようとしていますが、それを壊す1行がコメントアウトされています。また、 'renderPlot'の外で' hist'をなぜ呼び出すのか分かりません。実際の_最小限のreproducible_例は、大いに役立ちます。 – Axeman

答えて

1

です。私はまだ奇妙なエラーが出ていた。しかし、結論は次のとおりです。なぜ手動でbinwidthsと軸の制限を設定していますか?以下のコードは動作し、正しいヒストグラムを生成します。これがあなたが欲しい/必要としているものでないなら、あなたは何が必要なのかを説明できますか?

library(ggplot2) 
library(dplyr) 

# Define UI for application that draws a histogram 
ui <- shinyUI(fluidPage(

    # Application title 
    titlePanel("Contract Summary Application"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
    sidebarPanel(
     selectInput('Region', 
        'Region', 
        choices = levels(NotUnique$Region), selected = "Americas") 
    ), 

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

# Define server logic required to draw a histogram 
server <- shinyServer(function(input, output) { 

    #Make the histogram plot with ggplot2 

    output$distPlot <- renderPlot({ 
    ggplot(NotUnique %>% filter(Region == input$Region), aes(True_Net)) + 
     geom_histogram(fill = "blue") + 
     xlab("Amount Spent ($)") + 
     ylab("Frequency") 


    }) 
}) 

# Run the application 
shinyApp(ui = ui, server = server) 
関連する問題