about to lose my mind- Shiny Errors

Hi everyone,

I am a student and I have an assignment that is due in couple of days. I am trying to run an app on shiny to make an interactive chart and it is giving me a different error every time.

  • I check that my directory is correct

  • I checked the encoding (UTF-8)

  • I check that I don't have any extra commas

I don't know what else do.

I tried to run this app that I got off shiny website but even this one is not working.


# 01-kmeans-app

palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",

  "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))

library(shiny)

ui <- fluidPage(

  headerPanel('Iris k-means clustering'),

  sidebarPanel(

    selectInput('xcol', 'X Variable', names(iris)),

    selectInput('ycol', 'Y Variable', names(iris),

      selected = names(iris)[[2]]),

    numericInput('clusters', 'Cluster count', 3,

      min = 1, max = 9)

  ),

  mainPanel(

    plotOutput('plot1')

  )

)

server <- function(input, output) {

  selectedData <- reactive({

    iris[, c(input$xcol, input$ycol)]

  })

  clusters <- reactive({

    kmeans(selectedData(), input$clusters)

  })

  output$plot1 <- renderPlot({

    par(mar = c(5.1, 4.1, 0, 1))

    plot(selectedData(),

         col = clusters()$cluster,

         pch = 20, cex = 3)

    points(clusters()$centers, pch = 4, cex = 4, lwd = 4)

  })

}

shinyApp(ui = ui, server = server)

the errors I get:

ERROR: argument "outputId" is missing, with no default

ERROR:resourcing (myfilepath)

I looked at this document from shiny but it didn't help me with this case.

I hope someone here can help me, Thank you all.

Could you be more specific about how are you trying to run the app (try to give detailed steps) and the error you are getting?
I can run the code in your example without a problem

1 Like

For example I am trying to run this simple code:

#ui.R
library(shiny)

ui<-fluidPage(
  titlePanel("Coral Type"),
  sidebarLayout(
    sidebarPanel(
    )
  ),
  
  mainPanel(
    plotOutput("plot")
  )
)


#server.R
library(ggplot2)
read the data first
mydata  <- read.csv("myfile.csv")

server<-function(input, output){
  
  output$plot <- renderplot({
    
    plot(mydata$x, mydata$y)
    
  })}


shinyApp(ui=ui, server=server)

I click "run app", and instead of getting an output I get this error pointing out to my directory file. Although I have my ui, server and app file in the same directory folder.

56%20am

Warning: Error in sourceUTF8: Error sourcing /Users/arub/Documents/NewR/ui.R
  [No stack trace available]

this is my ui and server for further clarification. Running them would also create the same error.

# ui.R
library(shiny)

fluidPage(
  titlePanel("Coral Type"),
  sidebarLayout(
    sidebarPanel(
    )
  ),
  
  mainPanel(
    plotOutput("plot")
  )
)

# server.R
library(shiny) 
library(ggplot2)
# read the data first
mydata  <- read.csv("myfile.csv")

function(input, output){
  
  output$plot <- renderplot({
    
    plot(mydata$x, mydata$y)
    
  })}

When you use a single file app you should call the script file app.R also, maybe your problem is with the encoding of your csv file, do you get the same error message when running the demo app with iris built-in dataset?

Yes, I called it app.R and saved it in the directory file.
My excel file is saved as csv UTF-8.
I don't get this error when I run the demo.

Any chance you can share your csv file so we can try to reproduce your issue? Do you have non ASCII characters on that csv file?

Here is the file

https://drive.google.com/file/d/1ps5ls5QCqR8SUXqTjv1rPf-7wa6gmeRH/view?usp=sharing

One of the problems with your example is that R is case sensitive and the function is renderPlot() not renderplot(), the other problems is that there are no variables called x or y in your dataset, so this won't work.

If I change those things in your code, it runs.

library(shiny)
library(ggplot2)
mydata  <- read.csv("myfile.csv")

ui<-fluidPage(
    titlePanel("Coral Type"),
    sidebarLayout(
        sidebarPanel(
        ),
        mainPanel(
            plotOutput("plot")
        )
    )
)

server<-function(input, output){
    
    output$plot <- renderPlot({
        
        plot(mydata$longitud, mydata$latitud)
        
    })}

shinyApp(ui=ui, server=server)

4 Likes

Thank you so much. It worked :slight_smile:

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.