# 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.
#
library(shiny)
library(DT)
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]]<- 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)