在闪亮的应用程序中使用data.table包

时间:2018-03-27 08:48:25

标签: r shiny data.table shinydashboard

我想在Shiny App中使用data.table包来提高速度。 但是,我不清楚如何根据用户输入选择正确的列。

以下示例适用于数据采用data.frame格式但不采用data.table格式的情况。

# load packages
library(data.table)
# global  ----------------------------------------
library(shiny)
# use cars dataset
data(cars)
# create datatable from cars data
cars <- as.data.table(cars)

# user interface ---------------------------------
ui <- fluidPage(

  sidebarLayout(
    selectInput(inputId = 'col',    label = 'column', choices = names(cars)),
    numericInput(inputId = 'filter',label = 'filter', value = 5)
  ),
    mainPanel(plotOutput("plot"))

)

# server ----------------------------------------
server <- function(input, output) {
   output$plot <- renderPlot({
     # filter example
      d1 <- cars[speed>input$filter,]
      x    <- d1[[input$col]]
      hist(x)
   })
}

# run app  --------------------------------------
shinyApp(ui = ui, server = server)

0 个答案:

没有答案
相关问题