无法使用闪亮的应用程序构建模型

时间:2016-04-06 14:46:15

标签: r shiny

我正在尝试创建一个闪亮的应用程序,用户将上传一个csv文件,并根据用户选择的列,闪亮的应用程序将创建模型,显示模型和摘要的情节。看起来,当我选择列时,xv和yv值不会从数据框中填充以构建模型。我意识到我必须提供一个最小的例子,但我是一个非常新的闪亮,真的不知道问题出在哪里。以下是整个代码,非常感谢任何帮助。

这是代码:

library(shiny)
library(shinydashboard)
library(leaflet)
library(data.table)
library(ggplot2)
library(usl)

ui <- pageWithSidebar(
  headerPanel("CSV Viewer"),
  sidebarPanel(
    fileInput('file1', 'Choose CSV File',
              accept=c('text/csv','text/comma-separated-values,text/plain','.csv')),
    tags$hr(),
    checkboxInput('header', 'Header', TRUE),
    fluidRow(
      column(6,radioButtons("xaxisGrp","X-Axis:", c("1"="1","2"="2"))),
      column(6,checkboxGroupInput("yaxisGrp","Y-axis:", c("1"="1","2"="2")))
    ),
    radioButtons('sep', 'Separator',
                 c(Comma=',', Semicolon=';',Tab='\t'), ','),
    radioButtons('quote', 'Quote',
                 c(None='','Double Quote'='"','Single Quote'="'"),'"'),
    uiOutput("choose_columns")
  ),
  mainPanel(
    tabsetPanel(
      tabPanel("Data", tableOutput('contents')),
      tabPanel("Plot",plotOutput("plot")),
      tabPanel("Summary",uiOutput("summary"))

    )
  )
)


####server

server <- function(input, output,session) {
  dsnames <- c()
  u<-
  data_set <- reactive({
    inFile <- input$file1
    data(specsdm91)
    if (is.null(inFile))
      return(specsdm91)

    data_set<-read.csv(inFile$datapath, header=input$header, 
                       sep=input$sep, quote=input$quote)
  })

  output$contents <- renderTable({data_set()})

  observe({
    dsnames <- names(data_set())
    cb_options <- list()
    cb_options[ dsnames] <- dsnames
    updateRadioButtons(session, "xaxisGrp",
                       label = "X-Axis",
                       choices = cb_options,
                       selected = "")
    updateCheckboxGroupInput(session, "yaxisGrp",
                             label = "Y-Axis",
                             choices = cb_options,
                             selected = "")
  })
  output$choose_dataset <- renderUI({
    selectInput("dataset", "Data set", as.list(data_sets))
  })

  usl.model <- reactive({

      df <- data_set()
     # print(df)
      gp <- NULL
      if (!is.null(df)){

        xv <- input$xaxisGrp
        yv <- input$yaxisGrp
        print(xv)
        print(yv)
        if (!is.null(xv) & !is.null(yv)){

          if (sum(xv %in% names(df))>0){ # supress error when changing files

            usl.model <- usl(as.formula(paste(yv, '~', xv)), data = df)

          }
        }
      }
      return(gp)
    }
  )


  ##plot
  output$plot = renderPlot({

    plot(usl.model())

 } )

  ##
 # output$summary <- renderUI({

  #  summary(usl.model())

  #}) 

  ##

  output$choose_columns <- renderUI({

    if(is.null(input$dataset))
      return()
    colnames <- names(contents)
    checkboxGroupInput("columns", "Choose columns", 
                       choices  = colnames,
                       selected = colnames)
  }) 
}
shinyApp(ui, server)

==

控制台出错:

Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Warning: Error in plot.window: need finite 'xlim' values
Stack trace (innermost first):
    81: plot.window
    80: localWindow
    79: plot.default
    78: plot
    77: plot
    76: renderPlot [C:\shiny\file/ui.R#98]
    68: output$plot
     1: shiny::runApp

1 个答案:

答案 0 :(得分:0)

错误原因是:在usl.model被动,您返回了gp,但您应该返回usl.model