我是r的新手,需要解决一个需要更改导入数据的数据类型并将其用于进一步使用的问题。
我在链接的同一行上发现了问题,但没有帮助。
R change columns types using shiny, rhandson and DT
下面附有示例代码,我需要对此代码进行修改,以使“变量信息”标签显示变量表和选项,以更改导入的数据集中的变量类型。
library(shiny)
ui<-fluidPage(tabsetPanel(type="pills",
tabPanel("Data Upload",
# App title ----
titlePanel("Uploading Files"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput("file1", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
# Horizontal line ----
tags$hr(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Input: Select quotes ----
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
# Horizontal line ----
tags$hr(),
# Input: Select number of rows to display ----
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head")
),
# Main panel for displaying outputs ----
mainPanel(
# Output: Data file ----
tableOutput("contents")
)
) ,hr(),
print("~~~~~~~~~~~~~~~~~~~~footer~~~~~~~~~~~~~~~~~~~~")
),
tabPanel("Variable Information"
),tabPanel("Create new Variables"
),tabPanel("Correlations"
))
)
server <- shinyServer(function(input,output){
output$contents <- renderTable({
req(input$file1)
tryCatch(
{
df <- read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
},
error = function(e) {
# return a safeError if a parsing error occurs
stop(safeError(e))
}
)
if(input$disp == "head") {
return(head(df))
}
else {
return(df)
}
})
})
shinyApp(ui,server)