我将数据从excel电子表格上传到Shiny,其中包含\ r \ n和selectInput的共同名称不允许我选择它们。 R中有解决方法吗?
任何建议都将不胜感激!
library(shiny)
D = matrix(runif(400), nrow = 20)
colnames(D) = c("PROTECT",
"SAFER\r\nLines",
"Name",
"County",
"For Profit",
"Health\r\nInspection",
"Quality\r\nMeasures",
"Staffing",
"2014\r\nCensus",
"Total\r\nAdmissions",
"% Admissions\r\nw/ LOS: 100+",
"# of Days\r\nAssessed",
"Cumulative\r\nCensus",
"% Antibacterial\r\nUsage",
"2014 Total\r\nDischarges",
"% Discharge\r\nto Hospital",
"% Discharges to Hospital\r\nw/ Infx based on Primary\r\n& Other Diagnoses",
"Avg. Elixhauser\r\nScore",
"Any MDRO",
"High Frequency of Bath/Shower\r\n(5+ days/wk)")
ui <- fluidPage(
titlePanel("Summaries"),
tabsetPanel(
tabPanel("Matching Variables Info",
sidebarPanel(
selectInput("col1", "First Column", colnames(D)),
selectInput("col2", "Second Column", colnames(D), colnames(D)[19])
),
# Show summaries of columns choosen above
mainPanel(
verbatimTextOutput("dataInfo")
)
)
)
)
server <- function(input, output){
output$dataInfo <- renderPrint({
summary(D[, c(input$col1, input$col2)])
})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
\r\n
是Windows新行字符,可能是因为原始数据在Excel中包含多行的单元格。
您可以将它们转换为空格:
colnames(D) <- gsub("\r\n"," ", colnames(D))