2017-07-20 8 views
-1

これは、私はこのコードを持っている光沢のあるアプリケーションに関する: データモデルは次のとおりです。R:CBINDフォーマットとして使用csvファイル

2 \t 3 \t 4 \t 4 \t 2 
 
6 \t 2 \t 3 \t 1 \t 0 
 
4 \t 1 \t 1 \t 0 \t 4 
 
3 \t 2 \t 2 \t 3 \t 5 
 
2 \t 3 \t 5 \t 4 \t 0 
 
1 \t 2 \t 2 \t 2 \t 1 
 
5 \t 5 \t 0 \t 3 \t 4

> #This function is repsonsible for loading in the selected file 
> filedata_DM <- reactive({ 
>  infile <- input$datafile 
>  if (is.null(infile)) { 
>  # User has not uploaded a file yet 
>  return(NULL) 
>  } 
>  read.csv(infile$datapath,header=FALSE) }) 
>  performanceMatrix <- cbind(
>  c(-120.0,-150.0,-100.0,-60,-30.0,-80,-45.0), 
>  c(-284.0,-269.0,-413.0,-596,-1321.0,-734,-982.0),    
>  c(5.0,2.0,4.0,6,8.0,5,7.0),     
>  c(3.5,4.5,5.5,8,7.5,4,8.5),  
>  c(18.0,24.0,17.0,20,16.0,21,13.0) ) 




# results 
    output$filetable_result <- renderPrint({ 
    Electre_tri(performanceMatrix, 
         alternatives, 
         profiles, 
         profiles_names, 
         criteria, 
         minmaxcriteria, 
         criteriaWeights, 
         IndifferenceThresholds, 
         PreferenceThresholds, 
         VetoThresholds, 
         lambda=NULL) 

    }) 

私はピカピカで入力からcsvファイルを読み込みますこのファイルのようなアプリ「fileInput( "file"、 "File")、

ここでは、cbind関数で数値を指定する代わりにcsvデータ(テーブル)を使いたいと思っています!

大変助かります。 `

+0

あなたが読んだデータにアクセスする場合は、私はちょうど 'filedata_DM()を使用してトリックを行うと思いますか? –

+0

ありがとうございます!しかし動作しません!問題はどのように私はcsvファイルをcbind関数で表現された形式に変換できますか?(ベクトルとしてcsvデータを使用) – user2870763

+0

csvファイルがどのように表示されるかの例がないので、わかりにくいです。 –

答えて

0

ありがとう!最後に、このコードを使用して動作します:

#This function is repsonsible for loading in the selected file 
    filedata_DM <- reactive({ 
    infile <- input$datafile 
    if (is.null(infile)) { 
     # User has not uploaded a file yet 
     return(NULL) 
    } 
    read.csv(infile$datapath,header=TRUE) 
    }) 


    # statistics 
    output$filetable_result <- renderPrint({ 
    data2=filedata_DM() 
    performanceMatrix <- cbind(
     c(data2$v1), 
     c(data2$v2),    
     c(data2$v3),     
     c(data2$v4),  
     c(data2$v5) 
    ) 
    Electre_tri(performanceMatrix, 
         alternatives, 
         profiles, 
         profiles_names, 
         criteria, 
         minmaxcriteria, 
         criteriaWeights, 
         IndifferenceThresholds, 
         PreferenceThresholds, 
         VetoThresholds, 
         lambda=NULL) 

    }) 
0

これが私の作品:

library(shiny) 

ui <- fluidPage(
    sidebarLayout(
    shiny::fileInput("datafile", 'Choose CSV File'), 
     mainPanel(
     tableOutput("filetable_result") 
    ) 
    ) 
) 

server <- function(input, output) { 

    filedata_DM <- reactive({ 
    infile <- input$datafile 
    if (is.null(infile)) { 
     # User has not uploaded a file yet 
     return(NULL) 
    } 
    read.csv(infile$datapath,header=FALSE) 
    }) 

    output$filetable_result <- renderTable(filedata_DM()) 
} 

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

あなたは、それは反応だから、あなたがfiledata_DM()で読み取られたデータにアクセスする必要があります。したがって、変数に入れて、この変数をデータフレームとして使用しないでください。reactive()はデータフレームではないオブジェクトを返すためです。

関連する問題