2017-04-21 68 views
0

我有一個應用程序可以生成一個文本文件。我使用\n將文本放在新行上。如果我在本地運行應用程序,則下載的txt文件具有正確的輸出。但是,如果我在Shiny Server上運行該應用程序,則文本不會在新行上打印,即\n似乎不起作用。下面是一個例子程序:用Shiny Server的新行( n)寫入文本文件

ui <- fluidPage(title = "", 
       sidebarLayout(
        sidebarPanel(
        numericInput("num", "Number of lines to paste", 3), 
        actionButton("gen", "Generate text with new lines"), 
        downloadButton("downloadWeld", "Download") 
       ), 
        mainPanel(
        verbatimTextOutput("vtxt") 
       )) 

) 

server <- function(input, output) { 

    values <- reactiveValues() 
    values$df <- c() 

    observeEvent(input$gen,{ 
    values$df <- NULL  
    values$df <- paste0("E",input$num,"\n") 

    for(i in 1:input$num) 
     values$df <- paste0(values$df, "hello\n",i,"\nworld\n") 
    }) 

    output$vtxt <- renderText({ 
    values$df 
    }) 

    output$downloadWeld <- downloadHandler(
    filename <- function() { 
     paste0(input$num,"fname.txt") 
    }, 

    content <- function(file) { 
     writeLines(values$df, file) 
    }, 
    contentType = "text/csv" 
) 

}  
shinyApp(ui = ui, server = server) 

這是我sessionInfo地方:

R version 3.3.1 (2016-06-21) 

Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1 

locale: 
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252 
[3] LC_MONETARY=English_United Kingdom.1252 
[4] LC_NUMERIC=C       
[5] LC_TIME=English_United Kingdom.1252  

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] ggplot2_2.2.1 shiny_1.0.2 

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.7  assertthat_0.1 digest_0.6.10 mime_0.5   
[5] grid_3.3.1  R6_2.1.2   plyr_1.8.4  xtable_1.8-2  
[9] jsonlite_1.0  gtable_0.2.0  scales_0.4.1  lazyeval_0.2.0 
[13] labeling_0.3  tools_3.3.1  munsell_0.4.3 httpuv_1.3.3  
[17] colorspace_1.2-6 htmltools_0.3.5 tibble_1.2 

和服務器:

R version 3.3.3 (2017-03-06) 
Platform: x86_64-pc-linux-gnu (64-bit) 
Running under: Ubuntu 16.04.2 LTS 

locale: 
[1] LC_CTYPE=en_GB.UTF-8  LC_NUMERIC=C    LC_TIME=en_GB.UTF-8  
[4] LC_COLLATE=en_GB.UTF-8  LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 
[7] LC_PAPER=en_GB.UTF-8  LC_NAME=C     LC_ADDRESS=C    
[10] LC_TELEPHONE=C    LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C  

attached base packages: 
[1] stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] pool_0.1.0   data.table_1.9.6  sqldf_0.4-10   RSQLite_1.0.0  
[5] gsubfn_0.6-6   proto_0.3-10   RMySQL_0.10.9  DBI_0.5-1   
[9] dplyr_0.5.0   ggthemes_2.2.1  scales_0.4.1   plyr_1.8.4   
[13] shinydashboard_0.5.1 shinythemes_1.1.1 markdown_0.7.7  shiny_1.0.2   
[17] ggplot2_2.2.1  

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.8  magrittr_1.5  munsell_0.4.3 colorspace_1.3-2 xtable_1.8-0  R6_2.2.0   
[7] tcltk_3.3.3  tools_3.3.3  grid_3.3.3  gtable_0.2.0  htmltools_0.3.5 lazyeval_0.2.0 
[13] assertthat_0.1 digest_0.6.11 tibble_1.2  mime_0.4   labeling_0.3  jsonlite_1.1  
[19] chron_2.3-47  httpuv_1.3.3 

任何想法,爲什麼我不能在正確的輸出服務器應用?

回答

1

我發現了answer的另一個線程。這是因爲閃亮的服務器上的應用程序都與Java運行,因此新的線是用保存:

\r\n

運行時,我想在本地也沒有必要對Java轉換。