Ich möchte einen ausgewählten Spaltentyp eines bisher importierten Datensatzes ändern. Die Operationen sollten in einer glänzenden App durchgeführt werden. Die Daten sind in csv file. In diesem Datensatz heißt die Spalte, die geändert werden soll, "Datum", idealerweise sollte es jedoch möglich sein, den Namen der Spalte einzugeben, welcher Typ geändert werden soll.Ändern Sie den Spaltentyp des importierten Datensatzes in shiny
Der Code, den ich geschrieben habe:
ui <- fluidPage(
titlePanel("Test"),
mainPanel(
fluidRow(
column(5,
fileInput('file1', "Input a csv file:"),
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv'),
checkboxInput('header', 'Header', TRUE)),
column(3,
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
',')
),
column(3,
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"')
)
),
tableOutput("first.two"),
fluidRow(
column(4,
textInput("time.var", h3("Input time variable:"),
value = ""))
),
p(strong("Variables to choose from:"), textOutput("possible.variables")),
p(strong("Classes of variables"), textOutput("variable.classes"))
)
)
server <- function(input, output){
dset.in <- reactive({
infile <- input$file1
if(is.null(infile)){
return(NULL)
}
df <- read.csv(infile$datapath, header = input$header,
sep = input$sep,quote = input$quote)
return(df)}
)
# Change column type to date
# When three lines below are commented out, the code works
dset.in()$date.input <- observeEvent({
dset.in()[,input$time.var] <- lubridate::date_decimal(dset.in()[,input$time.var])
})
output$first.two <- renderTable({head(dset.in(), 2)})
output$possible.variables <- renderText(
names(dset.in())
)
output$variable.classes <- renderText(
sapply(dset.in(), class)
)
}
shinyApp(ui = ui, server = server)
Es wird folgende Fehler erzeugt:
Warning in if (!is.na(attribValue)) { :
the condition has length > 1 and only the first element will be used
Warning in charToRaw(enc2utf8(text)) :
argument should be a character vector of length 1
all but the first element will be ignored
Warning in body(fun) : argument is not a function
Warning: Error in eval: argument "expr" is missing, with no default
Stack trace (innermost first):
44: eval
43: makeFunction
42: exprToFunction
41: observeEvent
40: server [#16]
4:
3: do.call
2: print.shiny.appobj
1:
Error in eval(call("function", args, body), env) :
argument "expr" is missing, with no default