Passing user specifications as arguments to dplyr within Shiny

前端 未结 2 1523
一生所求
一生所求 2020-12-31 21:04

I\'m writing a new Shiny app, and I would like to stay within the Hadleyverse by using dplyr commands for data manipulation. I want Shiny to print a table showing only the t

2条回答
  •  执念已碎
    2020-12-31 21:26

    You may also want to look at arrange_ (see vignette). Really nice for in Shiny apps.

    The 1st option does what you want. The 2nd is cleaner but not exactly what you are looking for. I guess the 3rd option would be ideal but desc_ is not a function. Might be a nice addition :)

    input <- list()
    input$top3 <- "mpg"
    
    mtcars %>%
      arrange_(paste0("desc(",input$top3,")"))  %>%
      head(n=3)
    
    mtcars %>%
      arrange_(input$top3)  %>%
      tail(n=3)
    
    # desc_ is not a function (yet)
    mtcars %>%
      arrange(desc_(input$top3)) %>%
      head(n=3)
    

提交回复
热议问题