match.arg(position)中的错误:“ arg”必须为NULL或Shiny应用中的字符向量

时间:2019-01-17 19:41:41

标签: r shiny

大家下午好。

我正在创建一个应用程序分析工具,并在match.arg(position)中不断出现错误:'arg'必须为NULL或字符向量。我已经研究了几天,但似乎找不到问题。我感谢任何有第二眼的人,他们也许可以看看我可能会缺少什么。非常感谢!

library(shiny)
library(ggplot2)
library(stringr)
library(dplyr)
library(DT)
library(tools)
library(lubridate)
library(data.table)
library(plotly)

dtCLIPKey <- as.data.frame(updated_dtCLIPKey_11_16)

min_date <- min(dtCLIPKey$Date_1)
max_date <- max(dtCLIPKey$Date_1)

dtCLIPKey <- as.data.table(dtCLIPKey)


dtCLIPKey[,Short.NameN := .N,by="Short.Name"]

#NEED TO REMEMBER TO GET COUNT RIGHT TO INCLUDE HOURS AND DAY LIMITATION

dtCLIPKey$Short.NameRank <-frankv(dtCLIPKey$Short.NameN, ties.method = "dense")

# Define UI for application that plots features of movies
ui <- navbarPage("JRSS Application Analysis",


  #First NavBar Page
  tabPanel("Aggregate",



  # Sidebar layout with a input and output definitions
  sidebarLayout(

    # Inputs
    sidebarPanel(

      wellPanel(
        h3("Plotting"),      # Third level header: Plotting

        # Explanatory text
        HTML(paste0("Trend will be based on traffic samples from the following date selection. 
                    Pick dates between ", min_date, " and ", max_date, ".")),

        # Break for visual separation
        br(), br(),

        # Date input
        dateRangeInput(inputId = "date",
                       label = "Select dates:",
                       start = "2018-09-01", end = "2018-10-31",
                       min = min_date, max = max_date,
                       startview = "year") 
        ),


       # Select variable for x-axis
        selectInput(inputId = "hours", 
                       label = "Hour:",
                       choices = levels(factor(unique(dtCLIPKey$Hour_1))), 
                       selected = "1"),

      #Number of Applications 
        sliderInput("freq",
                   "Top N Applications:",
                    min = 1,  max = 40, value = 10),

      wellPanel(
        # Show data table
        checkboxInput(inputId = "show_data",
                      label = "Show data table",
                      value = TRUE)
      ),

      # Built with Shiny by RStudio
      br(), br(),
      h5("Built with",
         img(src = "https://www.rstudio.com/wp-content/uploads/2014/04/shiny.png", height = "30px"),
         "by",
         img(src = "https://www.rstudio.com/wp-content/uploads/2014/07/RStudio-Logo-Blue-Gray.png", height = "30px"),
         ".")

    ),



    # Output:
    mainPanel(

      tabsetPanel(type = "tabs",
                  # Tab 1: Barchart
                  tabPanel(title = "Barchart", 
                           plotOutput(outputId = "barchart"),
                           br(),
                           h5(textOutput("description")),
                           br(),
                           plotOutput(outputId = "boxplot")
                  ),

                  # Tab 2: ScatterPlot
                  tabPanel(title = "ScatterPlot", 
                           plotOutput(outputId = "scatterplot"),
                           plotOutput(outputId = "scatterplot2")
                           ),


                   # Tab 3: Data
                  tabPanel(title = "Data", 
                           br(),
                           DT::dataTableOutput(outputId = "traffictable"))
        )#MainPanel
      )#Sidebarpanel
    )#sidebarpayout
  ),#tabPanel



  tabPanel("App selection",


    # Inputs


    sidebarLayout(  

    sidebarPanel(

        wellPanel(
        selectInput(inputId = "App1", 
                 label = "Application",
                 choices = unique(dtCLIPKey$Short.Name), 
                 selected = "Application.XXX"),        

        # Break for visual separation
        br(), br(),

        # Break for visual separation
        br(), br(),

        # Date input
        dateRangeInput(inputId = "dateapp",
                       label = "Select app dates:",
                       start = "2018-09-01", end = "2018-10-31",
                       min = min_date, max = max_date,
                       startview = "year") 
        ),


      # Select variable for x-axis
      selectInput(inputId = "hoursapp", 
                  label = "Hour:",
                  choices = levels(factor(unique(dtCLIPKey$Hour_1))), 
                  selected = "1")),

       # Select variables to download
       wellPanel(
         checkboxGroupInput(inputId = "selected_var",
                     label = "Select variables:",
                     choices = c("Date" = "Date_1", 
                                 "IP Pair" = "IPPair", 
                                 "Computer Name" = "comp_name", 
                                 "Computer Type" = "comp_type_string", 
                                 "Group" = "Group"), 
                     selected = "Application")
                     )#wellpanel
                   )#sidebarpanel
                  )#sidebarlayout
                )#Tabpanel



# Output:
      mainPanel(

      tabsetPanel(type = "tabs",
              # Tab 1: Barchart
              tabPanel(title = "Violin", 
                       plotOutput(outputId = "histapp1")
                       ),#TablPanel
              tabPanel(title = "Trend", 
                       plotOutput(outputId = "lineapp1")
              ),
              tabPanel(title = "Plot by Variable", 
                       plotOutput(outputId = "scattervar"),
                       plotOutput(outputId = "boxplotvar")
              )
              )#tabsetPanel
      )#MainPanel
     #sidebarPanel




# Define server function required to create the scatterplot
server <- function(input, output, session) {



  # Create a subset of data filtering for selected time frame
  traffic_selected <- reactive({
    req(input$date) # ensure availablity of value before proceeding
    filter(dtCLIPKey, Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.NameRank > (max(dtCLIPKey$Short.NameRank)-input$freq))
  })

  # Create a subset of data filtering for selected application
  app_selected <- reactive({
    req(input$date) # ensure availablity of value before proceeding
    filter(dtCLIPKey, Date_1 >= input$dateapp[1] & Date_1 <= input$dateapp[2] & Hour_1 == input$hoursapp & Short.Name == input$App1)
  })
  app_selected_var <- reactive({
    req(input$date) # ensure availablity of value before proceeding
    filter(dtCLIPKey, Date_1 >= input$dateapp[1] & Date_1 <= input$dateapp[2] & Hour_1 == input$hoursapp & Short.Name == input$App1)
  })


  # Create the plot
  output$barchart <- renderPlot({
    req(input$date)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
          filter(Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.NameRank > (max(dtCLIPKey$Short.NameRank)-input$freq))


    ggplot(dtCLIPKey_selected_date, aes(x = Short.Name, y = Short.NameN, fill = Date_1)) +
      geom_bar(stat = "identity", width = 0.5, position = "dodge") +
      coord_flip()


  })


  output$histapp1 <- renderPlot({
    req(input$dateapp)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      filter(Date_1 >= input$dateapp[1] & Date_1 <= input$dateapp[2] & Hour_1 == input$hoursapp & Short.Name == input$App1)


    p <- ggplot(dtCLIPKey_selected_date, aes(x = Date_1, y = log(dt))) 
    p + geom_violin() + geom_boxplot(width = .1, fill = "blue", outlier.colour = NA) +
    stat_summary(fun.y = median, geom = "point", fill = "white", shape = 21, size = 2.5)




  })

  output$lineapp1 <- renderPlot({
    req(input$dateapp)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      filter(Date_1 >= input$dateapp[1] & Date_1 <= input$dateapp[2] & Hour_1 == input$hoursapp & Short.Name == input$App1)


    ggplot(dtCLIPKey_selected_date, aes(x = Date_1, y = mean(dt))) +
      geom_line() + 
      geom_point()


  })





  output$boxplot <- renderPlot({
    req(input$date)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      mutate(Date_1 = as.Date(Date_1)) %>% # convert thtr_rel_date to Date format
      filter(Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.NameRank > (max(dtCLIPKey$Short.NameRank)-input$freq))

    ggplot(dtCLIPKey_selected_date, aes(x=Short.Name, y=log(dt), group = Short.Name)) + 
      geom_boxplot() + stat_summary(fun.y = "mean", geom = "point", shape=23, size=3, fill="blue") + ggtitle("Log of Latency by Date") + theme(plot.title = element_text(hjust = 0.5)) + labs(x= "Date", y= "Log of Latency (in microsecs)") + 
      coord_flip() +
      facet_grid(~ Date_1)

  })

  output$scatterplot <- renderPlot({
    req(input$date)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      mutate(Date_1 = as.Date(Date_1)) %>% # convert thtr_rel_date to Date format
      filter(Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.NameRank > (max(dtCLIPKey$Short.NameRank)-input$freq))

    ggplot(dtCLIPKey_selected_date, aes(x=log(Short.NameN), y=log(dt), color = Short.Name)) + 
      geom_point() +
      facet_grid(~Date_1)

  })

  output$scatterplot2 <- renderPlot({
    req(input$date)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      mutate(Date_1 = as.Date(Date_1)) %>% # convert thtr_rel_date to Date format
      filter(Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.NameRank > (max(dtCLIPKey$Short.NameRank)-input$freq))

    ggplot(dtCLIPKey_selected_date, aes(x=log(Short.NameN), y=log(dt), color = Short.Name)) + 
      geom_point() 

  })

  output$scattervar <- renderPlot({
    req(input$date)
    req(input$selected_var)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      mutate(Date_1 = as.Date(Date_1)) %>% # convert thtr_rel_date to Date format
      filter(Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.Name == input$app1)

    ggplot(dtCLIPKey_selected_date, aes(x=log(Short.NameN), y=log(dt), color = Short.Name)) + 
      geom_point() 

  })


  output$scattervar <- renderPlot({
    req(input$date)
    req(input$selected_var)
    dtCLIPKey_selected_date <- dtCLIPKey %>%
      mutate(Date_1 = as.Date(Date_1)) %>% # convert thtr_rel_date to Date format
      filter(Date_1 >= input$date[1] & Date_1 <= input$date[2] & Hour_1 == input$hours & Short.Name == input$app1)
    dtCLIPKey_selected_date <- subset(dtCLIPKey_selected_date, select = c(Short.Name, dt, input$selected_var))  
    ggplot(dtCLIPKey_selected_date, aes(x=input$selected_var, y=log(dt), color = Short.Name)) + 
      geom_boxplot() 

  })


  # Print data table if checked
  output$traffictable <- DT::renderDataTable(
    if(input$show_data){
      DT::datatable(data = traffic_selected()[, 1:6], 
                    options = list(pageLength = 10), 
                    rownames = FALSE)
    }
  )

}

# Create Shiny app object
shinyApp(ui = ui, server = server)

0 个答案:

没有答案