2016-07-07 1 views
1

イムをレコード数を取得します失われた私は、データセットを読み込む際に、どのように私はベストプラクティスがであるべきである(あなたのglobal.Rファイルにあなたのlibraryコールと任意のread_*機能を持っているだろうシャイニーServerは、私は少しだ光沢のある学び、Excelシートに読み込み、UI</p> <p>にExcelシートの内容とレコード数の両方を表示しようとしているデータフレームに

# Server Code 
server <- shinyServer(function(input, output) { 

    # Read the Data in 
library(xlsx) 

    # Output the actual Table 
    output$contents <- renderTable({ 
    test_df <- read.xlsx(inFile$datapath,1) 
    test_df 
    )}) 

    # Output the number of records to check 
    output$text <- renderText({ 
    paste("Number of records is:", nrow(test_df)) 
    }) 
}) 

答えて

2

で読んだデータフレームを参照してくださいserver.Rとui.R. global.Rと同じディレクトリがWebアプリケーションの先頭に解析され、ファイルはuiとserverの両方で利用可能になります(ただし、ここではサーバ内でのみ必要です)。

だから、のようなもの:

#in globar.R 
library(xlsx) 
test_df <- read.xlsx(inFile$datapath,1) 

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

    # Output the actual Table 
    output$contents <- renderTable({ 
    test_df 
    )}) 

    # Output the number of records to check 
    output$text <- renderText({ 
    paste("Number of records is:", nrow(test_df)) 
    }) 

}) 

は正常に動作するはずです。

+0

こんにちは、@LyzandeR、これは素晴らしいです。私はglobar.Rと呼ばれるもう1つのRスクリプトファイルを作成する必要があります。光沢のあるアプリケーションは自動的にapp.Rとserver.Rのようにそこにあることを知っています。 –

+0

まさに。 shinyは、ui.Rとserver.Rを探すのと同じ方法でglobal.Rを探すようにプログラムされています。 – LyzandeR

関連する問題