Home > database >  Misspecifying argument error in shiny app
Misspecifying argument error in shiny app

Time:03-19

I have the shiny app below in which I try to present a descriptives table but my app breaks down with error:

Did you misspecify an argument?
  54: <Anonymous>
Error : `...` is not empty.





library(tidyverse)
library(shiny)
library(matrixStats)
library(tibble)
library(knitr)
library(kableExtra)
    Abstract_50<-structure(list(ID = c("UC_Ba9vCsY19LF7-gc46lWQQ", "UC_k6e2PPDUnxEdMJC9Q044g"
), AbstractName = c("ABC 1", "ABC 2"), Country = c("US", "US"
), Category = c("Gaming", "Comedy"), MadeK = c("No", "No"), SChan = c("Yes", 
"Yes"), Language = c("en", "EN"), URL1 = c("NA", "NA"), URL2 = c("NA", 
"NA"), `2018-03` = c(NA_real_, NA_real_), `2018-04` = c(NA_real_, 
NA_real_), `2018-05` = c(NA_real_, NA_real_), `2018-06` = c(NA_real_, 
NA_real_), `2018-07` = c(NA_real_, NA_real_), `2018-08` = c(NA_real_, 
NA_real_), `2018-09` = c(NA_real_, NA_real_), `2018-10` = c(NA_real_, 
NA_real_), `2018-11` = c(NA_real_, NA_real_), `2018-12` = c(NA_real_, 
NA_real_), `2019-01` = c(NA_real_, NA_real_), `2019-02` = c(NA_real_, 
NA_real_), `2019-03` = c(NA_real_, NA_real_), `2019-04` = c(NA_real_, 
NA_real_), `2019-05` = c(NA_real_, NA_real_), `2019-06` = c(NA_real_, 
NA_real_), `2019-07` = c(NA_real_, NA_real_), `2019-08` = c(NA_real_, 
NA_real_), `2019-09` = c(NA_real_, NA_real_), `2019-10` = c(NA_real_, 
NA_real_), `2019-11` = c(NA_real_, NA_real_), `2019-12` = c(NA_real_, 
NA_real_), `2020-01` = c(NA_real_, NA_real_), `2020-02` = c(NA_real_, 
NA_real_), `2020-03` = c(NA_real_, NA_real_), `2020-04` = c(NA_real_, 
NA_real_), `2020-05` = c(NA_real_, NA_real_), `2020-06` = c(NA, 
87710), `2020-07` = c(NA, 162416), `2020-08` = c(NA, 187892), 
    `2020-09` = c(NA, 374661), `2020-10` = c(NA, 449634), `2020-12` = c(NA, 
    1328523), `2021-01` = c(NA, 1525466), `2021-02` = c(NA, 1836399
    ), `2021-03` = c(NA, 2752575), `2021-04` = c(86334, 1520546
    ), `2021-05` = c(165124612, 3205193), `2021-06` = c(392264433,1534225), `2021-07` = c(282087438, 704348), `2021-08` = c(142305290, 
    49416984), `2021-09` = c(103659781, 49469088), `2021-10` = c(124671803, 
    20090134), `2021-11` = c(195965776, 363679038), `2021-12` = c(216612017, 
    774113580), `2022-01` = c(376009215, 796724246), `2022-02` = c(193946191, 
    599590598)), row.names = c(NA, -2L), class = c("tbl_df", 
"tbl", "data.frame"))
    
shinyApp(
  
  ui = fluidPage(
    selectInput("month", "Month:",
                choices = colnames(Abstract_50)[10:56],multiple=T,selected=colnames(Abstract_50)[10:14]),
    htmlOutput("tableset")
  ),
  
  server = function(input, output) {
    Ind<-Abstract_50[,c(4,10:56)] %>% 
      group_by(Category) %>%
      summarise(across(everything(), sum))
    
    Ind2<-reactive({
      Ind <- Ind[,c("Category",input$month), drop = FALSE]
      
    })
    Ind3<-reactive(Ind2() %>% remove_rownames %>% column_to_rownames(var="Category"))

    Descs<-reactive(
      Descs2<-tibble(Mean = rowMeans(Ind3(), na.rm = TRUE), 
                     Median = rowMedians(as.matrix(Ind3()), na.rm = TRUE),
                     SD=rowSds(as.matrix(Ind3()),na.rm = T),
                     MAD=rowMads(as.matrix(Ind3(),na.rm=T)),
                     MIN=rowMins(as.matrix(Ind3(),na.rm=T)),
                     MAX=rowMaxs(as.matrix(Ind3(),na.rm=T)),
                     VAR=rowVars(as.matrix(Ind3(),na.rm=T)),
                     RANGE=rowRanges(as.matrix(Ind3(),na.rm=T)),
                     QUANTILES=rowQuantiles(as.matrix(Ind3()), na.rm = TRUE)[, c(2, 4)]),
      
      Descs2<-as.data.frame(Descs2),
      rownames(Descs2)<-rownames(Ind3()),
      Descs2
    )
    
    
    
    
    output$tableset <- renderText({
      kable(Descs()) %>%
        kable_styling(
          font_size = 15,
          bootstrap_options = c("striped", "hover", "condensed")
        ) 
    })
  },
  
  options = list(height = 500)
  
)

CodePudding user response:

In the code, there are places where the OP specified , at the end of a line e.g.

 Descs2<-as.data.frame(Descs2),
 rownames(Descs2)<-rownames(Ind3()),

-full code

 ui = fluidPage(
    selectInput("month", "Month:",
                choices = colnames(Abstract_50)[10:56],multiple=TRUE,selected=colnames(Abstract_50)[10:14]),
    htmlOutput("tableset")
  )
  
  server = function(input, output) {
    Ind<-Abstract_50[,c(4,10:56)] %>% 
      group_by(Category) %>%
      summarise(across(everything(), sum))
    
    Ind2<-reactive({
      Ind <- Ind[,c("Category",input$month), drop = FALSE]
      
    })
    Ind3<-reactive({
         req(Ind2())
         Ind2() %>% remove_rownames %>% column_to_rownames(var="Category")
    }
         
         )
    
    
    Descs<-reactive({
         req(Ind3())
         tmp <- Ind3()
      Descs2<-tibble(Mean = rowMeans(tmp, na.rm = TRUE), 
                     Median = rowMedians(as.matrix(tmp), na.rm = TRUE),
                     SD=rowSds(as.matrix(tmp),na.rm = TRUE),
                     MAD=rowMads(as.matrix(tmp,na.rm=TRUE)),
                     MIN=rowMins(as.matrix(tmp,na.rm=TRUE)),
                     MAX=rowMaxs(as.matrix(tmp,na.rm=TRUE)),
                     VAR=rowVars(as.matrix(tmp,na.rm=TRUE)),
                     RANGE=rowRanges(as.matrix(tmp,na.rm=TRUE)),
                     QUANTILES=rowQuantiles(as.matrix(tmp), na.rm = TRUE)[, c(2, 4)])
      
      Descs2<-as.data.frame(Descs2)
      rownames(Descs2)<-rownames(tmp)
      Descs2
    }
    )
    
    
    
    
    output$tableset <- renderText({
      kable(Descs()) %>%
        kable_styling(
          font_size = 15,
          bootstrap_options = c("striped", "hover", "condensed")
        ) 
    })
  }
  
shinyApp(ui = ui, server = server, options = list(height = 500))
  • Related