2016-06-23 34 views
0

link to data in xlsx file (data is in 4th sheet)光沢のあるライブラリー(光沢) ライブラリ(のxlsx)は、複数のエクスポート<a href="https://drive.google.com/open?id=0BzAJnxmL2vZodmJSRU1XWnNVSHM" rel="nofollow">,link to data in csv file</a><br>

shinyUI(fluidPage(

    titlePanel("Tim O'Leary"), 
    sidebarLayout(
    sidebarPanel(
     fileInput('file1', 'Choose File', 
      accept=c('text/csv', 
        'text/comma-separated-values,text/plain', 
        c(".txt",'.csv'))), 
    downloadButton('downloadData', 'Download'), 
    tags$hr(), 
    checkboxInput('header', 'Header', TRUE), 
    radioButtons('sep', 'Separator', 
       c(Comma=',', 
       Semicolon=';', 
       Tab='\t'), 
       '\t'), 
    radioButtons('quote', 'Quote', 
       c(None='', 
       'Double Quote'='"', 
       'Single Quote'="'"), 
       '"') 

), 
mainPanel(

    #tableOutput('contents') 
    tabsetPanel(
    tabPanel("RawTable", tableOutput('contents')), 
    tabPanel("Table1", tableOutput('a')), 
    tabPanel("Table2", tableOutput("b")), 
    tabPanel("Table3", tableOutput("c")) 

) 
) 
) 
)) 

library(shiny) 
    library(xlsx) 

shinyServer(function(input, output) { 

rawData <- reactive({ 
filet <- input$file1 
    if(is.null(filet)) return() 
    data <- read.csv(filet$datapath) 
    }) 

    #dtableInput<- reactive({ 
     # if(is.null(rawData())) 
    # return() 
    # data<-rawData()   
    #}) 

    a <- reactive({ 
    a <- subset(rawData(), AssertionString == "10046") 
    a 
}) 

    b <- reactive({ 
    b <- subset(rawData(), AssertionString == "10074") 
    b 
    }) 

c <- reactive({ 
    c <- subset(rawData(), AssertionString == "10179") 
    c 
}) 

# workBook <- reactive({ 
# processor <- createWorkbook() 
# page1 <- createSheet(wb=processor, sheetName="iam") 
    # page2 <- createSheet(wb=processor, sheetName="tim") 
    # page3 <- createSheet(wb=processor, sheetName="oleary") 
    # page4 <- createSheet(wb=processor, sheetName="J") 
    #addDataFrame(x=rawData(), sheet=page1) 
# addDataFrame(x=a(), sheet=page2) 
# addDataFrame(x=b(), sheet=page3) 
    # addDataFrame(x=c(), sheet=page4) 
    # wb <- saveWorkbook(processor,"processorData") 
# wb 
#}) 

output$contents <- renderTable({ 
     rawData() 
     }) 

    output$a <- renderTable({ 
      a() 
     }) 

     output$b <- renderTable({ 
     b() 
     }) 

    output$c <- renderTable({ 
     c() 
      }) 

     output$downloadData <- downloadHandler(
     filename = function() {paste("file_name", '.cvs')}, 
     content = function(file){ 
     write.csv(a(), file="file_name") 
      #write.xlsx2(a(), file="file_name.xlsx", sheetName="sheet1") 
      #write.xlsx2(b(), file="file_name.xlsx", sheetName="sheet2",         append=T) 
     }) 
#rbind allows you to connect dfs in column like manner 

    }) 

これらは光沢のあるRで私のUIとサーバスクリプトであり、私はエクスポートしようとしている1つのワークブックRにシートをエクセルrawData、a、b、およびcをExcelフレームワークに組み込み、各データフレームは独自のシートを持ちます。私はcsvファイルを読み込み、そのようにエクスポートしようとしましたが、write.csvを使用するのに必要な方法でエクスポートすることができる関数が見つかりません。私はその後、raw.xDataがwrite.xlsxのために大きすぎるため、.xlsxとしてインポートしようとしました。ダウンロードボタンをクリックしたときにwrite.xlsx2を使用した場合、無限の時間だけロードされますがダウンロードされません。何でもどんな助けやアドバイスもありがとうございます

+0

AssertonStringは、自分のデータセット内の列の名前で、これらのAssertionString番号でデータセットをフィルタリングしています。私は問題がちょうど私のdownloadHandlerにあると信じていますが、私はこの作業を得ることができません –

+0

サンプルデータを提供してください –

+0

私はコメントで作業しているデータを添付する方法はありますか? –

答えて

0

あなたのデータをダウンロードすることはできませんが、ここでは動作する例です。任意のcsvファイルをヘッダーでアップロードして列を指定すると、xlsxファイルをダウンロードできます。このファイルでは、選択した列の一意の値に基づいてcsvファイルが複数のタブに分割されます。 write.xlsxの機能はかなり遅いので、csvファイルのサイズに応じてしばらく待つ必要があります。

library(shiny) 

ui <- shinyUI(fluidPage(

    titlePanel("CSV Splitter"), 

    sidebarLayout(
     sidebarPanel(
     fileInput("file", "Upload csv file", accept="text/csv"), 
     uiOutput("column_ui"), 
     downloadButton("download") 
    ), 

     mainPanel(
    ) 
    ) 
)) 

server <- shinyServer(function(input, output) { 

    data <- reactive({ 
     if (is.null(input$file)) { 
      return(NULL) 
     } else { 
      return(read.csv(input$file$datapath, header=TRUE)) 
     } 
    }) 

    output$column_ui <- renderUI({ 
     selectInput("column", "Select a column to split by unique values", unique(names(data()))) 
    }) 

    output$download <- downloadHandler(
     filename = "result.xlsx", 
     content = function(file) { 
      column_data = data()[[input$column]] 
      unique_values = unique(column_data) 
      write.xlsx(data()[data()[[input$column]] == unique_values[1],], file, as.character(unique_values[1])) 
      for (i in 2:length(unique_values)) { 
       write.xlsx(data()[data()[[input$column]] == unique_values[i],], file, as.character(unique_values[i]), append = TRUE) 
      } 
     } 
    ) 

}) 

# Run the application 
shinyApp(ui = ui, server = server) 
+0

ありがとう!やってみます –

関連する問題