:Rmarkdownファイルから
<input type="file" id="files" name="files[]" multiple />
<output id="list">
<a href="https://<myName>.shinyapps.io/<myShinyRmarkdownFile>/?"id>linkText</a>
</output>
ビット私が望むことをする方法を、th質問のタイトルはおそらく誤解を招いていました。私はデータを光沢のあるものにしたいと思っていました。それで、分析してpdfを作ることができました。
次のデータは、YouTubeのビデオと対応するserver.Rファイルを輝かしくするのに役立ちました。
https://www.youtube.com/watch?v=HPZSunrSo5M
https://github.com/aagarw30/R-Shinyapp-Tutorial/blob/master/fileinput/server.R
おかげで、 ジョン
編集:
server.Rファイルは以下の通りです:
library(shiny)
# use the below options code if you wish to increase the file input limit, in this example file input limit is increased from 5MB to 9MB
# options(shiny.maxRequestSize = 9*1024^2)
shinyServer(function(input,output){
# This reactive function will take the inputs from UI.R and use them for read.table() to read the data from the file. It returns the dataset in the form of a dataframe.
# file$datapath -> gives the path of the file
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
})
# this reactive output contains the summary of the dataset and display the summary in table format
output$filedf <- renderTable({
if(is.null(data())){return()}
input$file
})
# this reactive output contains the summary of the dataset and display the summary in table format
output$sum <- renderTable({
if(is.null(data())){return()}
summary(data())
})
# This reactive output contains the dataset and display the dataset in table format
output$table <- renderTable({
if(is.null(data())){return()}
data()
})
# the following renderUI is used to dynamically generate the tabsets when the file is loaded. Until the file is loaded, app will not show the tabset.
output$tb <- renderUI({
if(is.null(data()))
h5("Powered by", tags$img(src='RStudio-Ball.png', heigth=200, width=200))
else
tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
})
})
"重要なビット":
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)
# [ john's edit: more code can be put here to alter data before passed to data(). eg:
# o=read.delim(file=file1$datapath)
# convertData(o)
#]
})
反応的な意味で、入力ファイル$ file(つまりファイルチューザー)を待ってから、選択したファイルを読み込みます。個人的には、私はread.tel(...)ではなくread.delim(....)を使います。データ(データフレーム)は現在「データ()」に格納され、そのように呼ばれます。したがって:
output$table <- renderTable({
if(is.null(data())){return()}
data()
})
上記のことは、表示する前にdata()にデータがあることを確認することに注意してください。
データは、()と同じで関数に渡すことができるデータフレームのとおりであった:私は長い時間のために困惑していたもう一つの問題は、PDFファイルをレンダリング/エクスポートする方法である
new.dataframe=do.something.with.the.data(data())
。
output$download_pdf <- downloadHandler(
filename = function() {
paste('pdf_name', sep = '.','pdf')
},
content = function(file) {
src <- normalizePath('rmarkdownFile.Rmd')
print(paste("src",src,sep=": "))
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(src, 'rmarkdownFile.Rmd')
df.A=data.frame(functionA(data()))
df.B=data.frame(functionB(data()))
out=rmarkdown::render('rmarkdownFile.Rmd',pdf_document())
file.rename(out,file)
}
)
私は例えば、それがすべて働い持っていませんでした、あなたはそれを名前を変更する最初のファイルをコピーすることになって、それが問題を引き起こしているようですしている、私は今のためにそれを残してきました。
df.Aとdf.Bは、rmarkdownファイルに渡されるデータフレームです。他に何もする必要はありません。 rmarkdownの中では、通常のようにそれらを使用してください。
あなたの家のコンピュータで(上の設定で)pdfがプロジェクトディレクトリに保存されます。 shinyapps.ioでアップロードされたアプリケーションとして使用すると、ファイル保存場所ウィンドウが表示されます。
私は上記が役立つことを願っています。
あなたは単にそれを行うことはできません。 Webサーバーがユーザーのファイルに単純にアクセスできる場合、セキュリティ上の大きな問題になります。ユーザーが自分のサーバーにデータをアップロードし、そこからアクセスするための特定の方法を提供する必要があります。 –