闪亮的错误is.na()应用于类型' NULL'的非(列表或向量)。

时间:2015-05-07 20:07:38

标签: r shiny

我的闪亮应用程序存在问题。我尝试使第二个selectInput(model)依赖于第一个selectInput(marka)中的选择,但它仍然不起作用。

我找到了这个主题Using the input from updateSelectInput,它可以在我的计算机上运行,​​所以我对我的数据做了完全相同的事情(在PogromcyDanych包中)。不幸的是,它不起作用,我无望。我收到了警告信息:

Warning in run(timeoutMs) :
  is.na() applied to non-(list or vector) of type 'NULL'
Warning in run(timeoutMs) : 

下面是我的server.Rui.R个文件:

library(shiny)
library(PogromcyDanych)
library(dplyr)

shinyServer(function(input, output, session) {

   dane <- auta2012

   observe({
      marka <- input$Marka
      ktore <- dane %>%
         filter(Marka == marka) %>%
         arrange(Model) %>%
         select(Marka, Model)
      updateSelectInput(session, "model", 
                        choices = levels(factor(ktore$Model)), 
                        selected = levels(factor(ktore$Model))[1])
   })

   dane.cena <- reactive({
      dane %>% 
         filter(Marka == input$Marka, Model == input$Model)
   })

})

UI:

library(shiny)
library(PogromcyDanych)
dane <- auta2012

shinyUI(fluidPage(
  titlePanel("Znajdź swój samochód!"),
  sidebarLayout(
    sidebarPanel(
      selectInput("marka",
                  "Wybierz markę",
                  levels(dane$Marka),
                  levels(dane$Marka)[1]),

      selectInput("model",
                  "Wybierz model",
                  levels(dane$Model),
                  levels(dane$Model)[1])
    ),

    mainPanel(
      h1("Ceny samochodów:"),
      br(),
      tabsetPanel(
        tabPanel("Boxplot", plotOutput("boxplot", width = 500)),
        tabPanel("Histogram", plotOutput("histogram", width = 500)),
        tabPanel("Podsumowanie", verbatimTextOutput("podsumowanie")),
        tabPanel("Tabela", tableOutput("tabela"))
      )
    )
  )
))

1 个答案:

答案 0 :(得分:2)

您在选择输入ID中出现了sintax错误! ("Marka""Model"有大写字母)

  selectInput("Marka",
              "Wybierz markę",
              levels(dane$Marka),
              levels(dane$Marka)[1]),

  selectInput("Model",
              "Wybierz model",
              levels(dane$Model),
              levels(dane$Model)[1])