2013-08-26 1 views
0

Im пытается создать веб-приложение с новой функцией RStudio Shiny. Я пытаюсь модель космического пространства ETS. Я хочу указать тип модели вручную (Полужирный текст на сервере.R). Я ввожу данные в кавычки в server.R. Если мы дадим iputs внутри кавычек, это не займет. Не могли бы вы мне помочь ...Модель ETS с использованием Shiny

ui.R

library(shiny) 
shinyUI(pageWithSidebar(
    headerPanel("Forecast", "Flowserve"), 
    sidebarPanel(
    fileInput('file1', 'Select csv file', 
       accept=c('text/csv') 
      ), 
    checkboxInput('header', 'Header', TRUE), 
    radioButtons('sep', 'Separator', 
       c(Comma=',', Semicolon=';', Tab='\t') 
       ), 
    tags$hr(), 
    numericInput("startyear", "Start Year and Month",2010), 
    sliderInput("month","",min=1, max=12,value=1, step=1, animate=T), 

    tags$hr(), 
    selectInput("error", "Error Type", list("Multiplicative"="M","Additive"="A")), 
    selectInput("trend", "Trend Type", list("Multiplicative"="M","Additive"="A", "Null"="N")), 
    selectInput("seasonal", "Seasonal Type", list("Multiplicative"="M","Additive"="A", "Null"="N")), 
    submitButton("UPDATE") 
), 

    mainPanel(

    tabsetPanel(
    tabPanel("Data", tableOutput('contents')), 
    tabPanel("Time Plot", plotOutput('tsplot')), 
    tabPanel("Forecast", plotOutput('plotforecast')) 
      ) 
    ) 
)) 

server.R

library(shiny) 
library(forecast) 
shinyServer(function(input,output){ 

    data1 = reactive({ 
    inFile<-input$file1 
    if(is.null(inFile)) 
    return(NULL) 
    read.csv(inFile$datapath, header=input$header, sep=input$sep) 
    }) 
output$plotforecast<-renderPlot(function(){ 
    datats<-ts(data1(), start=c(input$startyear,input$month), frequency=12) 
    model<-ets(datats, model="input$error input$trend input$seasonal") 
    fit1<-fitted(model) 
    future1<-forecast(model, h=4, level=c(95,97.5)) 
    p2<-plot.forecast(future1,shadecols=c("yellow","orange"), xlab=expression(bold(Year)), ylab=expression(bold(Demand))) 
    print(p2) 
    }) 
+0

Попробуйте заменить 'model <-ets (datats, ** model =" input $ error input $ trend input $ seasonal "**)' by 'model <-ets (datats, model = paste0 (input $ error, ввод $ тренд, ввод $ сезонный)). – sgibb

+0

Большое спасибо Sgibb ... Это работает ... Не могли бы вы рассказать, что значит «paste0»? – Punith

+0

Обратите внимание, что явные разрывы строк ('
') не нужны, я удалил их. –

ответ

1

Вы должны заменить model<-ets(datats, **model="input$error input$trend input$seasonal"**) на model<-ets(datats, model=paste0(input$error, input$trend, input$seasonal)), потому что model аргумент ожидать 3 -Письмо-строка. paste0 конкатенации векторов символов (см. ?paste0).