简体   繁体   English

如果数据巨大(即2GB),我如何在R Shiny中查看整个数据

[英]How can i see the whole data in R shiny if the data is huge(i.e 2gb)

I am loading the data in the shiny server.Data is a CSV file of around 2 GB .Its not showing the whole data or its taking to long to load but the head option is working . 我正在将数据加载到闪亮的服务器中。数据是一个大约2 GB的CSV文件。它没有显示整个数据或加载花费了很长时间,但是head选项正在运行。 This is the code which i have already tried, This coe is working for small files. 这是我已经尝试过的代码,此coe正在处理小型文件。

enter code here

ui <- fluidPage(

  #App title ---- 
  titlePanel("Uploading Files"),

  # Sidebar layout with input and output definitions ----
  sidebarLayout(

    # Sidebar panel for inputs ----
    sidebarPanel(

      # Input: Select a file ----
      fileInput("file1", "Choose CSV File",
                multiple = TRUE,
                accept = c("text/csv",
                           "text/comma-separated-values,text/plain",
                           ".csv")),

      # Horizontal line ----
      tags$hr(),

      # Input: Checkbox if file has header ----
      checkboxInput("header", "Header", TRUE),

      # Input: Select separator ----
      radioButtons("sep", "Separator",
                   choices = c(Comma = ",",
                               Semicolon = ";",
                               Tab = "\t"),
                   selected = ","),

      # Input: Select quotes ----
      radioButtons("quote", "Quote",
                   choices = c(None = "",
                               "Double Quote" = '"',
                               "Single Quote" = "'"),
                   selected = '"'),

      # Horizontal line ----
      tags$hr(),

      # Input: Select number of rows to display ----
      radioButtons("disp", "Display",
                   choices = c(Head = "head",
                               All = "all"),
                   selected = "head")

    ),

    # Main panel for displaying outputs ----
    mainPanel(

      # Output: Data file ----
      tableOutput("contents"),
      tableOutput("df")


    )

  )
)

# Define server logic to read selected file ----
server <- function(input, output) {

  output$contents <- renderTable({

    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, head of that data file by default,
    # or all rows if selected, will be shown.

    req(input$file1)

    df <- read.csv(input$file1$datapath,
                   header = input$header,
                   sep = input$sep,
                   quote = input$quote)

    if(input$disp == "head") {
      return(head(df))
    }
    else {
      return(df)
    }

  })
  options(shiny.maxRequestSize=10000*1024^2)
  df <- renderTable(df)

}
# Run the app ----enter code here
shinyApp(ui, server)

i am expecting whole dataframe in "all" option, but its not working for lkarge data frames. 我期望整个数据框都在“所有”选项中,但不适用于lkarge数据框。

library(shiny)
library(DT)

ui <- fluidPage(

    #App title ---- 
    titlePanel("Uploading Files"),

    # Sidebar layout with input and output definitions ----
    sidebarLayout(

        # Sidebar panel for inputs ----
        sidebarPanel(

            # Input: Select a file ----
            fileInput("file1", "Choose CSV File",
                      multiple = TRUE,
                      accept = c("text/csv",
                                 "text/comma-separated-values,text/plain",
                                 ".csv")),

            # Horizontal line ----
            tags$hr(),

            # Input: Checkbox if file has header ----
            checkboxInput("header", "Header", TRUE),

            # Input: Select separator ----
            radioButtons("sep", "Separator",
                         choices = c(Comma = ",",
                                     Semicolon = ";",
                                     Tab = "\t"),
                         selected = ","),

            # Input: Select quotes ----
            radioButtons("quote", "Quote",
                         choices = c(None = "",
                                     "Double Quote" = '"',
                                     "Single Quote" = "'"),
                         selected = '"'),

            # Horizontal line ----
            tags$hr(),

            # Input: Select number of rows to display ----
            radioButtons("disp", "Display",
                         choices = c(Head = "head",
                                     All = "all"),
                         selected = "head")

        ),

        # Main panel for displaying outputs ----
        mainPanel(

            # Output: Data file ----
            dataTableOutput("contents")


        )

    )
)

# Define server logic to read selected file ----
server <- function(input, output) {

    output$contents <- renderDataTable ({

        # input$file1 will be NULL initially. After the user selects
        # and uploads a file, head of that data file by default,
        # or all rows if selected, will be shown.

        req(input$file1)

        df <- read.csv(input$file1$datapath,
                       header = input$header,
                       sep = input$sep,
                       quote = input$quote)

        if(input$disp == "head") {
            df <- head(df)
        } else {}
        df
    })


}
# Run the app ----enter code here
shinyApp(ui, server)

Use the DT library, "all" works, but might take a lot of time to render. 使用DT库,“所有”都可以使用,但是渲染可能需要很多时间。 I also modified your code, since there were some errors/ bad practice like df <- renderTable(df) which you anyway do not need here. 我还修改了您的代码,因为有一些错误/不良做法,例如df <- renderTable(df) ,您无论如何都不需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 R Shiny 和 plotly 中处理大量数据? - How to work with huge data in R Shiny and plotly? 如何将数据框中的列滞后到新列中 - 即第 1 行成为新列中的第 2 行? - how can I lag a column in a data frame into a new column - i.e row 1 becomes row 2 in the new column? 是否有更好的(即矢量化)方法将列名称的一部分放入R中的数据帧的行中 - Is there a better (i.e vectorised) way to put part of a column name into a row of a data frame in R 在 R Shiny 中,如何使用我在该observeEvent 之外的observeEvent(按钮单击)中生成的数据? - In R shiny, how can I use data that I generated in an observeEvent (button click) outside of that observeEvent? 如何将我制作的 data.frame 放入 R 的 shiny 框中 - How can I put a data.frame I made inside a shiny box in R 我可以收集闪亮的数据吗? - Can I collect data on shiny? 如何在 R 中安排嵌套数据(即带父子关系的数据)? - How to arrange nested data (i.e., data with parenting) in R? 如何扩展我的R Shiny应用程序以获得更大的数据输入? - How can I scale my R Shiny app for bigger data inputs? 如何根据 R Shiny 中 Leaflet 地图的输入过滤数据表? - How can I filter a data table based on input from a Leaflet map within R Shiny? 在R Shiny应用程序中将鼠标悬停在某个点上时如何查看数据? - How to see data while hovering over a point in a R Shiny app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM