我正在尝试使用输入文本中的列名加载csv文件,如果header = FALSE。 col.names(c()中的textInput有点奇怪。当我输入textInput作为" a"," b"," x"输入文本被读取as" \" a \",\" b \",\" x \""。
library(shiny)
shinyServer(function(input, output) {
colm <- renderText({input$cols})
head <- renderText({input$header})
contents <- reactive({
infile <- input$file1
if (head() =="TRUE") {
if (is.null(input$file1)) {return(NULL)}
read.csv(infile$datapath)}
else
{
if (is.null(input$file1)) {return(NULL)}
read.csv(infile$datapath, header = input$header,sep=",",col.names=c(str(input$cols)))
}})
output$data <- renderTable({contents()})
output$man <- renderText({colm()})
output$men <- renderText({head()})
})
UI.R
library(shiny)
shinyUI(fluidPage(
titlePanel("The Ace!"),
navbarPage("Calulus@Work",
tabPanel("About Tool",p("The tool designed for single place for Analytics.")),
navbarMenu("Data Load",
tabPanel("Delimter",
sidebarLayout(
sidebarPanel(fileInput('file1', 'Choose file to upload',
accept = c('text/csv',
'text/comma-separated-values',
'text/tab-separated-values',
'text/plain','.csv','.tsv'
)),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
textInput('cols',"Enter column names"),
radioButtons('sep', 'Separator',c(Comma=',',Semicolon=';',
Tab='\t'),','),
radioButtons('quote', 'Quote',
c(None='','Double Quote'='"','Single Quote'="'"),'"'),
tags$hr(),
),
mainPanel(
tableOutput('contents')
textOutput("man"),
textOutput("men")
))),
)
)#navbarPage
)#fluidpage
)#shinyUI
Error:
chr "\"a\",\"b\",\"x\""
Error in read.table(file = file, header = header, sep = sep, quote = quote, :
more columns than column names
请帮助解决这个问题