[英]How to fix the error "file must be a character string or connection" when running my Shiny app in R?
My application is giving me problems once it is asked to execute the function Conjoint.一旦要求执行 function 联合,我的应用程序就会出现问题。 If I use the function only on R there are no problems, the problems appear when I use it in my shiny app.如果我只在 R 上使用 function 没有问题,当我在我的 shiny 应用程序中使用它时会出现问题。
library(shiny)
library(conjoint)
ui <- fluidPage(
fileInput('file1', 'Carica il file delle preferenze',
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
fileInput('file2', 'Carica il file del profilo',
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
fileInput('file3', 'Carica il file dei nomi dei livelli',
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
textOutput("TEST")
)
server <- function(input, output) {
pref <- reactive({
req(input$file1)
read.csv(input$file1$datapatht)
})
profiles <- reactive({
req(input$file2)
read.csv(input$file2$datapatht)
})
levelnames <- reactive({
req(input$file3)
read.csv(input$file3$datapatht)
})
output$TEST<-renderTable({
Conjoint(y=pref(),x=profiles(),z=levelnames())
})
}
shinyApp(ui, server)
You are receiving the error in the question title because of a typo: datapatht
should be datapath
.由于拼写错误,您在问题标题中收到错误: datapatht
应该是datapath
。 I also recommend simply using accept = ".csv"
since any .csv
file must necessarily have that file ending.我还建议简单地使用accept = ".csv"
因为任何.csv
文件都必须以该文件结尾。
Both are implemented below:两者都在下面实现:
library(shiny)
library(conjoint)
ui <- fluidPage(
fileInput('file1', 'Carica il file delle preferenze',
accept = c(".csv")),
fileInput('file2', 'Carica il file del profilo',
accept = c( ".csv")),
fileInput('file3', 'Carica il file dei nomi dei livelli',
accept = c(".csv")),
textOutput("TEST")
)
server <- function(input, output) {
pref <- reactive({
req(input$file1)
read.csv(input$file1$datapath)
})
profiles <- reactive({
req(input$file2)
read.csv(input$file2$datapath)
})
levelnames <- reactive({
req(input$file3)
read.csv(input$file3$datapath)
})
output$TEST<-renderTable({
Conjoint(y=pref(),x=profiles(),z=levelnames())
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.