带有多个输入的闪亮表

时间:2018-10-27 21:31:32

标签: sorting input shiny

我想在具有多个输入的数据集下面创建闪亮的输出表。 我想选择型号,细分和年份。我怎样才能做到这一点?有没有一种方法可以放置按钮并对显示的数据进行排序? 谢谢。

df=data.frame(year=c(2018,2018,2017,2017,2017),model=c("mazda","ford","ford"
,"toyotta","mazda"),segment=c("c1","ax","ay","gv","c1"),sales=c(23,54,65,78,54))

1 个答案:

答案 0 :(得分:1)

精彩的library(DT)满足了上述所有要求,而无需定义任何输入或自定义过滤器逻辑:

library(shiny)
library(DT)

ui <- basicPage(
  h2("Car data"),
  DT::dataTableOutput("mytable")
)

server <- function(input, output) {

  df = data.frame(
    year = c(2018, 2018, 2017, 2017, 2017),
    model = c("mazda", "ford", "ford"
              , "toyotta", "mazda"),
    segment = c("c1", "ax", "ay", "gv", "c1"),
    sales = c(23, 54, 65, 78, 54)
  )

  output$mytable = DT::renderDataTable({
    df
  }, filter = "top", options = list(pageLength = 30))
}

shinyApp(ui, server)

screenshot