[英]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.