Problem reading and showing text file in shiny app

Hello,
I got the error "con is not a connection
can someone help me out?
my code:

> library(shiny)
library("tm")
library("SnowballC")
library("wordcloud")
library("RColorBrewer")
library("syuzhet")
library("ggplot2")
library(wordcloud2)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      textInput("caption1", "Caption", "Data Summary"),
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Result textfield",verbatimTextOutput("value1")) ,
        tabPanel("Result file input", verbatimTextOutput("contents")),
        tabPanel("Explanation", "writen by rob "), 
        
      ))))

server <- function(input, output) {
  
  output$value1 <- renderText({ input$caption1 })
  output$contents <- renderText({
    # 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.
    
    
    readLines(input$file1 )
  })
  inFile <- reactive({input$file1})
  if (is.null(inFile))
    return(NULL))
 }
shinyApp(ui, server)

Kind regards, Rob

you are trying to use input$file1 directly, but this is a variable that represents the return of a fileInput, which is a data.frame, the data.frame contains a column datapath, that is the actual path to the copy of the file as it is available to your app. so you should be looking to use input$file1$datapath for that role.

Thx nirgrahamuk it s working now indeed it was the "$datapath"
i adopte the my code now like this:

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      textInput("caption1", "Caption", "Data Summary"),
      fileInput("file1", "Choose CSV File",
                accept = c(
                  "text/csv",
                  "text/comma-separated-values,text/plain",
                  ".csv")
      ),
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Result textfield",verbatimTextOutput("value1")) ,
        tabPanel("Result file input", verbatimTextOutput("contents")),
        tabPanel("Explanation", "writen by rob "), 
        
      ))))

server <- function(input, output) {
  
  output$value1 <- renderText({ input$caption1 })
  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.
    req(input$file1)
    
    readtext::readtext(input$file1$datapath)
  })
  inFile <- reactive(write.table({input$file1}))
  if (is.null(inFile))
    return(NULL)
  
  }
shinyApp(ui, server)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.