【发布时间】:2014-10-18 09:23:24
【问题描述】:
我是 R 和 R Shiny 的新手。
对于我目前需要手动输入文件名的代码,我想概括一下,让用户选择工作目录和相应的文件名。
1、用户选择工作目录
然后闪亮能够将所有文件名存储在选定的工作目录下。类似于list.files()
2,那么box list files会列出选中wd下的所有文件名 并且用户可以检查应该显示哪个数据集
3、在主面板中 将显示带有标题的数据集的前 10 个实例
我试过的是
服务器.R
library(shiny)
setwd("C:/Users/HKGGAIT001/Google Drive/GA Project/Cargo/Cargo.Statistics/data/Hactl")
data1 <- read.csv(list.files()[1])
data2 <- read.csv(list.files()[2])
# Define server logic required to summarize and view the selected
# dataset
shinyServer(function(input, output) {
# Return the requested dataset
datasetInput <- reactive({
switch(input$dataset,
"data1" = data1,
"data2" = data2)
})
# Generate a summary of the dataset
output$summary <- renderPrint({
dataset <- datasetInput()
summary(dataset)
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
})
ui.R
library(shiny)
# Define UI for dataset viewer application
shinyUI(fluidPage(
# Application title
titlePanel("Shiny Text"),
# Sidebar with controls to select a dataset and specify the
# number of observations to view
sidebarLayout(
sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("data1", "data2")),
numericInput("obs", "Number of observations to view:", 10)
),
# Show a summary of the dataset and an HTML table with the
# requested number of observations
mainPanel(
verbatimTextOutput("summary"),
tableOutput("view")
)
)
))
情况类似于This website,而我的情况是请求用户选择本地工作目录。
感谢您的温柔帮助
【问题讨论】:
-
一个好的问题不仅包含一般任务描述,还包含解决任务所采取的步骤以及具体失败的地方。