简体   繁体   English

在 R 中运行我的 Shiny 应用程序时,如何修复错误“文件必须是字符串或连接”?

[英]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.

相关问题 闪亮的错误:“文件”必须是字符串或连接 - Shiny error: 'file' must be a character string or connection 运行应用程序时出现闪亮错误:match.arg(position) 中的错误:&#39;arg&#39; 必须为 NULL 或字符向量 - Shiny Error when running App: Error in match.arg(position) : 'arg' must be NULL or a character vector 如何修复我闪亮的应用程序中的hoverinfo错误? - How to fix the hoverinfo error in my shiny app? “文件”必须是字符串或连接 - 'file' must be a character string or connection 在 R 中运行 updateMatrixInput 函数时如何修复矩阵值? - How to fix a matrix value when running updateMatrixInput function in R shiny? 将R Shiny应用程序部署到Shinyapps.io时,出现“错误:oauth_listener()需要交互式环境”。 我怎样才能解决这个问题? - When I deploy my R shiny app to shinyapps.io, I get 'Error: oauth_listener() needs an interactive environment'. How can I fix this? 运行闪亮的应用程序时出现错误“无法打开连接” - error running shiny app “can not open connection” 当 shiny 应用程序通过单击按钮运行时,如何运行 R 脚本? - How to run an R script when the shiny app is running with click of a button? 如何将 css 文件添加到 R Shiny 以改进我的应用程序? - How to add a css file to R Shiny to improve my app? 错误:如果为正,列索引必须最多为 6 - R 中的闪亮应用错误 - Error in : Column indexes must be at most 6 if positive - Shiny App Error in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM