我是新手,R并且Shiny我的Shiny服务器上存储了一些数据文件.
我想要做的是根据用户选择选择一个文件,然后将该文件读入数据框.
我目前正在获取object not found error,虽然名称正在正确地传输到服务器UI.
这是一些代码,fisrt server.r
library(shiny)
library(datasets)
filenames<-list.files(path="~/qc",pattern="\\.csv$")
shinyServer(function(input,output){
output$choose_dataset<-renderUI({
selectInput("dataset","Data set",filenames)
})
output$data_table<-renderTable({
selFile<-get(input$dataset)
mydat<-read.csv(selFile$name,header=T)
head(mydat,50)
})
})
Run Code Online (Sandbox Code Playgroud)
这里是 ui.r
library(shiny)
shinyUI(pageWithSidebar(
headerPanel(
"Files Selection"
),
sidebarPanel(
uiOutput("choose_dataset")
),
mainPanel(
tabsetPanel(
tabPanel("plot",plotOutput("plot"),id="myplot"),
tabPanel("Data",tableOutput("data_table"),id="myTab"),
id="Plot_Data"
)
)
))
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我做了一些小改动,它对我有用.试着看看这对你有用.
在server.R我将selectInput()移动到UI.R,我也将文件名变量移动到UI.R.现在,因为input$dataset在文件中,您没有得到get()命令.
library(shiny)
library(datasets)
shinyServer(function(input,output){
output$data_table<-renderTable({
#selFile<-get(input$dataset)
mydat<-read.csv(input$dataset, header=T)
head(mydat,50)
})
})
Run Code Online (Sandbox Code Playgroud)
library(shiny)
filenames<-list.files(pattern="\\.csv$")
shinyUI(pageWithSidebar(
headerPanel(
"Files Selection"
),
sidebarPanel(
selectInput(inputId = "dataset",
label = "Choose Dataset",
filenames
)
),
mainPanel(
tabsetPanel(
tabPanel("plot",plotOutput("plot"),id="myplot"),
tabPanel("Data",tableOutput("data_table"),id="myTab"),
id="Plot_Data"
)
)
))
Run Code Online (Sandbox Code Playgroud)
试试这个,你不应该得到object not found错误.您可以使用这些文件作为基础,并在这些文件的基础上构建.
希望这可以帮助.