【发布时间】:2022-01-24 06:34:18
【问题描述】:
我正在开发一个读取 xpt 文件的 R 闪亮应用程序。
下面的代码读取一个csv文件并显示一个表格;但是,我正在寻找一种使用函数sasxport.get. 从 .xpt 文件中查看/显示相同内容的方法,有人可以帮助我如何在 R Shiny 中执行此操作吗?
app.R(目前它读取 csv)
## Only run examples in interactive R sessions
if (interactive()) {
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".csv")
),
tags$hr(),
checkboxInput("header", "Header", TRUE)
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output) {
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found.
inFile <- input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header = input$header)
})
}
shinyApp(ui, server)
}
【问题讨论】: