R shiny dashboard is not recognizing newly variables I have created in code

Hello Everyone,
As the Title of my post states, I am currently creating a R shiny dashboard and when I create a new variable (i.e. renaming a previous df that I now have filtered), R shiny is not finding the new variable and then reporting a "argument is of length zero" error.

I know that the code itself is correct because if I take that new variable separately and run it in a different R sheet, it works well and the variable is correctly added to the global environment.

However, like I said, in the R shiny dashboard code these new variables are not being added to the global environment.

Any help on this topic would be awesome! I really appreciate the help!

you are probably not making a reactive dataframe which would be the way to go for a shiny app.

Thank you so much for the help! Can you clarify the issue for me using the example I provide? This is part of my server function. The "filtereddata1" variable is not being recognized.

  server <- function(session, input, output) { output$plot1 <- renderPlot({

      filtereddata1 <-  filter(mergedTrainingdf, Date >= input$daterange[1] & Date <= input$daterange[2]) %>% 
                        filter(Team == input$Teaminput)
      if (input$category == "Player") {filterdata1 <- filtereddata1 %>% 
                                       filter(Playername %in% input$Playernameinput)
      if (input$category == "Overview") {filtereddata1 <- filtereddata1
      ggplot(filtereddata1, aes(x= Date, y = Weight)) +

you seem to have inconsistent spellings filtereddata1 filterdata1
In principle your code is fine and works


(mergedTrainingdf <- tibble(
  Date = seq.Date(
    from = Sys.Date() - 10,
    by = "day",
    length.out = 10
  Team = c(rep("A", 6), rep("B", 4)),
  Playername = letters[1:10],
  Weight = 1:10

ui <- fluidPage(
    label = "dates",
    start = Sys.Date() - 10,
    end = Sys.Date()
    label = "Teaminput",
    choices = unique(mergedTrainingdf$Team)
    label = "category",
    choices = c("Player", "Overview"), selected = "Player"
    label = "Playernameinput",
    choices = mergedTrainingdf$Playername,
    multiple = TRUE,
    selected = mergedTrainingdf$Playername

server <- function(session, input, output) {
  output$plot1 <- renderPlot({
    f1 <- filter(mergedTrainingdf, Date >= input$daterange[1] & 
                   Date <= input$daterange[2]) %>%
      filter(Team == input$Teaminput)

    if (input$category == "Player") {
      f2 <- f1 %>%
        filter(Playername %in% input$Playernameinput)
    if (input$category == "Overview") {
      f2 <- f1

    ggplot(f2, aes(x = Date, y = Weight)) +
      geom_point(size = 2)
shinyApp(ui, server)

Thanks a lot for the help. Spelling mistakes are not ideal...
However, even when fixing that, it still doesn't work.

I have had this problem a couple of times with my project. This project has two csv files that are inputted at the beginning of the code. csv file1 loaded correctly, however, I had the same issue where csv file 2 was not put into the global environment until I ran it in a different R file tab.

This issue has happened a few times.

i dont know what to change in my example of your code, to break it...

Thanks for looking into it for me. I must have an error somewhere in my code but it is obviously difficult to find.
I appreciate the help nonetheless

Here is a link with some resources regarding shiny debugging
Shiny debugging and reprex guide

This topic was automatically closed 21 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.