add a new dataset to a dataset list, get Warning: Error in !: invalid argument type.

8 views
Skip to first unread message

wech...@gmail.com

unread,
Apr 22, 2018, 9:11:41 AM4/22/18
to Shiny - Web Framework for R
Hello,
      i am trying to do :
                  1.    read a .csv file, add the new data to a exist list with a new name:   dataList <- list("iris"=iris,"mtcars"=mtcars),   dataList[[input$newdata]]<- read.csv(input$file1$datapath,....)
                   2.   select a dataset from the list  to view: selectInput("contentsIn","Choose a dataset:", choices=names(dataList), selected ="")

           but get Warning: Error in !: invalid argument type.  

         I appreciate if you can provide any comments.

My script is:
          
library(shiny)
library(DT)
#options(shiny.reactlog=TRUE)

dataList <- list("iris"=iris,"mtcars"=mtcars)
ui <- fluidPage(

  titlePanel("loading file"),

  sidebarLayout(

    sidebarPanel(

      fileInput("file1", "choose csv file",
                multiple = TRUE,
                accept = ("text/csv")),
      textInput("newdata", "Rename"),
      actionButton("change", "change"),
      hr(),
      radioButtons("sep", "separator",
                   choices = c(Comma=",", Semicolon = ";", Tab="\t"), selected=","),
      hr(),
      radioButtons("quote", "Quote", choices = c(None="", "Double Quote"='"', "Single Quote"="'"), selected = '"'),

      hr(),
      radioButtons("disp", "Display", choices = c(head="head", All="all"), selected = "head"),

      selectInput("contentsIn","Choose a dataset:", choices=names(dataList), selected ="")


    ),
    mainPanel(
      dataTableOutput("contentsOut")
    )
  )
)


server <- function(input, output){

  observeEvent(input$change, {
    #dataList[input$newdata]
    dataList[[input$newdata]]<- read.csv(input$file1$datapath,
                  header = input$header,
                  sep = input$sep,
                  quote = input$quote)
  }, ignoreInit = TRUE)


  getdata <- reactive({

    get(input$contentsIn)
  })


  output$contentsOut <- renderDataTable({

    if (input$disp=="head") { return (datatable(head(getdata())))}
    else {
      return (datatable(getdata()))
    }
  })

}

shinyApp(ui, server)


                 

Reply all
Reply to author
Forward
0 new messages