2016-08-23 7 views
0

シンプルなShiny Appを構築しようとしていますが、動作させることができません。私は状態を選択したいとアプリは、オゾンレベルのsample.measurementのためのその状態の平均を計算する必要があります。ここに私のui.Rコードは次のとおりです。ShinyのSelectInput

require(shiny) 
fluidPage(pageWithSidebar(
headerPanel("Ozone Pollution"), 
sidebarPanel(
h3('State'),selectInput("inputstate","Select State",state.name)), 
mainPanel(
h3('Results'),verbatimTextOutput("res") 
) 
)) 

そして、ここでは私のserver.Rプログラムは次のとおりです。

require(dplyr) 
library(shiny) 
shinyServer(
function(input, output) { 
stat_state<-reactive({filter(ozone_2015,State.Name==input$inputstate)}) 
output$res<- renderPrint({mean(stat_state$Sample.Measurement)}) 
} 
) 

任意のヒント?ありがとう.....

+0

この 'stat_state $ Sample.Measurement'をこの' stat_state()$ Sample.Measurement'に変更することがあります。 – zx8754

答えて

1

ozone_2015がどこに由来するのかわからないため、私はあなたのデータセットを複製できませんが、あなたの問題はあなたがこのような "反応"オブジェクトを参照していないと思います:

stat_stateは()

あなたが反応値と入力$変数を除いて、反応物を作るたら、変数の末尾に「()」で、それを参照する必要があります。

ここでは、コードの一部を別のデータセットで使用している例を示します。お役に立てれば。

require(shiny) 

ui <- 
fluidPage(pageWithSidebar(
    headerPanel("Population"), 
    sidebarPanel(
    h3('State'),selectInput("inputstate","Select State",state.name)), 
    mainPanel(
    h3('Results'),verbatimTextOutput("res") 
) 
)) 

server <- function(input,output){ 
    require(dplyr) 

    sample.data <- reactive({as.data.frame(state.x77)}) 

     stat_state <- reactive({sample.data()[which(row.names(sample.data()) == input$inputstate),]}) 
     output$res <- renderPrint({stat_state()$Population}) 
    } 
) 
} 


shinyApp(ui = ui, server = server) 
関連する問題