2017-06-11 3 views
0

私はRプログラミング(そしてStackOverflowも)に全く新しいので、Shinyパッケージを使って小さなRプロジェクトに取り組んでいました。今では、Shinyがすでにテンプレートを提供している.csvファイルをアップロードするか、ui.Rとserver.Rの形式でコードを記述する必要があります。しかし、私の問題は、Shinyが提供しているコードスニペットには、ブラウザーセクションと、ヘッダーとラジオボタンのセクレーター(カンマ、セミコロン、タブ)と引用符(なし、ダブル、シングル)のチェックボックスセクションが含まれていることです。Shinyのファイルアップロード機能の特定の部分を編集するには?

[1]

私はスクリプトを修正したので、ラジオボタンは表示されないように見えるので、参照セクションとヘッダーまたはセパレータまたは引用符は必要ありません。

# The code section starts here. 
# Original Script provided by Shiny. 
ui.R 

library(shiny) 

ui <- fluidPage(
titlePanel("Uploading Files"), 
sidebarLayout(
sidebarPanel(
    fileInput('file1', 'Choose CSV File', 
      accept=c('text/csv', 
        'text/comma-separated-values,text/plain', 
        '.csv')), 
    tags$hr(), 
    checkboxInput('header', 'Header', TRUE), 
    radioButtons('sep', 'Separator', 
       c(Comma=',', 
       Semicolon=';', 
       Tab='\t'), 
       ','), 
    radioButtons('quote', 'Quote', 
       c(None='', 
       'Double Quote'='"', 
       'Single Quote'="'"), 
       '"') 
), 
mainPanel(
    tableOutput('contents') 
) 
) 
) 


server.R file 

library(shiny) 

server <- function(input, output) { 
output$contents <- renderTable({ 

# input$file1 will be NULL initially. After the user selects 
# and uploads a file, it will be a data frame with 'name', 
# 'size', 'type', and 'datapath' columns. The 'datapath' 
# column will contain the local filenames where the data can 
# be found. 

inFile <- input$file1 

if (is.null(inFile)) 
    return(NULL) 

read.csv(inFile$datapath, header=input$header, sep=input$sep, 
     quote=input$quote) 
    }) 
    } 

shinyApp(ui=ui, server = server) 

Iは ​​

なくラジオ・ボックスを削除することができた第二の画像に示すように、ヘッダチェックボックス部を除去することができました。それをする方法について助言してください。事前にみなさんに感謝します。

答えて

0

私が正しくあなたの質問を理解している場合、私は知りませんが、あなたは単に2 radioButtons()を削除し、checkboxInput()uiからすることができます

ui <- fluidPage(
    titlePanel("Uploading Files"), 
    sidebarLayout(
    sidebarPanel(
     fileInput('file1', 'Choose CSV File', 
       accept=c('text/csv', 
         'text/comma-separated-values,text/plain', 
         '.csv')), 
     tags$hr() 
    ), 
    mainPanel(
     tableOutput('contents') 
    ) 
) 
) 

をそして3つの入力変数(input$headerを、削除または交換serverであなたのread.csv()からinput$setinput$quote):

server <- function(input, output) { 
    output$contents <- renderTable({ 

    inFile <- input$file1 

    if (is.null(inFile)) 
     return(NULL) 

    read.csv(inFile$datapath, header=T, sep=";") 
    }) 
} 
+0

どうもありがとうございました。私はui.Rのラジオボタンセクションを削除していましたが、server.Rのread.csv部分をread.csv(inFile $ datapath)として変更していました。多分、それが私が望む出力を得ていなかった理由です。あなたの迅速で貴重な提案についてもう一度感謝します。それは魅力的に機能しました。 –

関連する問題