3
나는 ggplot2를 사용하는 R 반짝이 응용 프로그램을 만들고 있습니다. 이 앱은 사용자가 업로드 한 csv 파일을 가져 와서 ggplot2를 사용하여 그래프로 그립니다.더 큰 데이터 입력을 위해 R Shiny 앱을 확장하려면 어떻게해야합니까?
내 응용 프로그램은 작은 CSV 입력 (20 행/열까지 말합니다)에 적합합니다. 내 애플 리케이션을 2MB + 범위의 파일에 대한 데이터 시각화에 유용하게 만들려고하고있다.
그러나 내 현재 상태에서는 큰 그래프로 분석 할 때 그래프가 쓸모가 없습니다. 문제를 재현 할 수 있도록 일부 코드 및 링크를 상대 CSV 파일에 게시합니다. 여기
는 예를 들어 데이터 세트입니다 : http://seanlahman.com/baseball-archive/statistics/, 버전 5.9.1에서 따기 아무것도 - 쉼표로 구분 된 버전X에 대한 'YearID를'그래프와 Appearances.csv에서 Y에 대한 'playerID'시도하고 당신이 표시되는 내용 내말은.
ui.R
library(shiny)
dataset <- list('Upload a file'=c(1))
shinyUI(pageWithSidebar(
headerPanel(''),
sidebarPanel(
wellPanel(
radioButtons('format', 'Format', c('CSV', 'TSV', 'XLSX')),
uiOutput("radio"),
fileInput('file', 'Data file')
),
wellPanel(
selectInput('xLine', 'X', names(dataset)),
selectInput('yLine', 'Y', names(dataset), multiple=T)
)
),
mainPanel(
tabsetPanel(
tabPanel("Line Graph", plotOutput('plotLine', height="auto"), value="line"),
id="tsp" #id of tab
)
)
))
server.R
library(reshape2)
library(googleVis)
library(ggplot2)
library(plyr)
library(scales)
require(xlsx)
require(xlsxjars)
require(rJava)
options(shiny.maxRequestSize=-1)
shinyServer(function(input, output, session) {
data <- reactive({
if (is.null(input$file))
return(NULL)
else if (identical(input$format, 'CSV'))
return(read.csv(input$file$datapath))
else if (identical(input$format, 'XLSX'))
return(read.xlsx2(input$file$datapath, input$sheet))
else
return(read.delim(input$file$datapath))
})
output$radio <- reactiveUI(function() {
if (input$format == 'XLSX') {
numericInput(inputId = 'sheet',
label = "Pick Excel Sheet Index",1)
}
})
observe({
df <- data()
str(names(df))
if (!is.null(df)) {
updateSelectInput(session, 'xLine', choices = names(df))
updateSelectInput(session, 'yLine', choices = names(df))
}
})
output$plotLine <- renderPlot(height=650, units="px", {
tempX <- input$xLine
tempY <- input$yLine
if (is.null(data()))
return(NULL)
if (is.null(tempY))
return(NULL)
widedata <- subset(data(), select = c(tempX, tempY))
melted <- melt(widedata, id = tempX)
p <- ggplot(melted, aes_string(x=names(melted)[1], y="value", group="variable", color="variable")) + geom_line() + geom_point()
p <- p + opts(axis.text.x=theme_text(angle=45, hjust=1, vjust=1))
p <- p + labs(title=paste("",tempX," VS ",tempY,""))
print(p)
})
})
대용량 데이터를 유지하는 선 그래프처럼 추세에 대한 또 다른 시각화를 생각할 수 없으므로 처음 언급 한 방법이 가장 적합하다고 보입니다. 유일한 문제는 사용자가 정확히 업로드하는 매개 변수를 모르는 것이므로 데이터를 집계하는 일반적인 방법이 있습니까? 예를 들어, 10,000 행의 데이터를 받았다면 데이터 포인트의 양을 줄이면 10,000/1,000을 나눌 수 있습니다. 따라서 1,000 열마다 평균을 구할 것입니다. 나는 개념을 이해하지만 R에서 그것을 구현하는 방법을 이해하지 못한다. – jeffrey
코멘트의 첫 번째 부분은 집계에 대해 묻지 만, 후반의 예제는 샘플링이다. 이를 위해 R ['sample'] (http://stat.ethz.ch/R-manual/R-devel/library/base/html/sample.html) 함수가 필요합니다 - 예제 [here]를보십시오 (https://gist.github.com/jcheng5/3239667). –
아마도 k- 클러스터링이 내 발을 더 잘 발달시킬 것이라고 생각하고 있습니다 ... – jeffrey