rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.38k stars 1.86k forks source link

Multiple column input into col.names from textInput - Bug #853

Closed calculus-ask closed 9 years ago

calculus-ask commented 9 years ago

If we input col.name = input$textinput in read.csv --> we are getting this bug... My sample file has three column without headers.. i have tried with several iterations and thought to report as bug. I have raised in earlier post, since that issue has been closed i am posting as new issue..

@wch please check.. cat is also not working

library(shiny)

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

      if (input$header== TRUE) 
      {
        infile <- input$file1
        if (is.null(input$file1)) {return(NULL)}
        read.csv(infile$datapath)
      }
    else
      {
        infile <- input$file1
        if (is.null(input$file1)) {return(NULL)}
        cols <- cat(input$value)
        read.csv(infile$datapath,header=FALSE,col.names=cols)
      }

})})

library(shiny) shinyUI(fluidPage(

titlePanel("The Ace!"), navbarPage("Calulus@Work",
tabPanel("About Tool" ), 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' )), checkboxInput('header', 'Header', TRUE), textInput("value","Enterhere","") ), mainPanel( tableOutput('contents')))))

         )#navbarPage

)#fluidpage )#shinyUI

Error: "a","b","c" Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names

calculus-ask commented 9 years ago

Tried using strsplit also..

library(shiny)

shinyServer(function(input, output, session) {

output$contents <- renderTable({

if (input$header== TRUE)
{
  infile <- input$file1
  if (is.null(input$file1)) {return(NULL)}
  read.csv(infile$datapath)
} 
else 
  {        
    infile <- input$file1
    if (is.null(input$file1)) {return(NULL)}
    tmp <- strsplit(input$value,",")
    read.csv(infile$datapath,header=FALSE,col.names=tmp)       
}

}) })

Error..

Error in read.table(file = file, header = header, sep = sep, quote = quote, : more columns than column names

calculus-ask commented 9 years ago

Tried with renderUI also.. cant figure the error in this.. kindly help on this issue..

library(shiny)

shinyServer(function(input,output,session) { output$contents <- renderTable ({ if (input$header== TRUE) { infile <- input$file1 if (is.null(input$file1)) {return(NULL)} heada <- read.csv(infile$datapath) }
})

output$number <- renderUI ({ num <- as.integer(input$nums) textInput <- lapply(1:num, function(i) {textInput(paste("text_",i),paste("value",i),"")}) do.call(sidebarPanel,textInput) })

output$contenta <- renderTable ({ if (input$header==FALSE) { num <- as.integer(input$nums) infile <- input$file1 if (is.null(input$file1)) {return(NULL)} headb <- read.csv(infile$datapath,header=FALSE,col.names=c(lapply(1:num, function(i) {input[[paste("text_",i)]]}))) } }) })

library(shiny) shinyUI(fluidPage(

titlePanel("The Ace!"), navbarPage("Calulus@Work",
tabPanel("About Tool" ), 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' )), checkboxInput('header', 'Header', TRUE), textInput("value","Enterhere","")

numericInput("nums","Enter here","1")

                                 ),
                               mainPanel(
                                 tableOutput('contents'),
                                 uiOutput('number'),
                                 tableOutput('contenta')
                                 ))))
         )#navbarPage

)#fluidpage )#shinyUI

Error in orig(name = name, shinysession = self) : unused arguments (name = name, shinysession = self)

wch commented 9 years ago

With the second version of your code, it sounds like you simply have the wrong number of columns in the header text.

For more on debugging shiny apps, see http://shiny.rstudio.com/articles/debugging.html