How to replace NULL in dataframe with 0?

I am new to Shiny. I have a program that allows users to import .csv file, and select axes to graph from that file. The program works when the data contains all numeric numbers; however, when there are NULL values, I get the following error: Can’t combine length and colors .

An example of data I am having trouble with is included below:

length y time colors
5 0 30 NULL
10 1 60 NULL
15 2 90 NULL

If I remove the colors column, the program will work fine, so I know the program will work if there are only numbers. I think I would need to use a replace() function, but I would appreciate any help. Thank you!

library(shiny)#load and attach package shiny
library(shinythemes)
library(data.table)
library(ggplot2)
library(tidyverse)

not_sel <- "Not selected"

main_page <- tabPanel(#create a tab panel for main_page
  title = "Data Plotter",#main_page tab titled Plot
  titlePanel("Data Plotter"),#panel titled Plot
  sidebarLayout( #create a layout with a sidebar and main area
    sidebarPanel(#side panel = inputs
      title = "Inputs",
      fileInput("csv_input","Select CSV File",accept = ".csv"),#first parameter is ID to call in server, text that appears, condition to accept
      selectInput("x_axis","Select x-axis",choices = c(not_sel)),#creates input in Inputs
      selectInput("y_axis","Select y-axis",choices = c(not_sel), selected = not_sel, multiple = TRUE),
      actionButton("run_button","Apply Changes",icon = icon("play")), #adds play icon
    ),
    mainPanel(#main panel are outputs
      tabsetPanel(#can divide output into separate viewable screens
        tabPanel(#first screen called Plot
          title = "Plot",
          plotOutput("plot_1") #make Plot screen output image
        )
      )
    )
  )
)
about_page <- tabPanel(
  title = "About",
  titlePanel("About"),#create a panel containing an application title
  "Created by NC",
  br(),#new line
  "June 2024"
)

ui <- navbarPage(#create a page with a top level navigation bar
  title = "Data Plotter",
  theme = shinytheme('sandstone'),
  main_page,
  about_page
)

server <- function(input, output){
  options(shiny.maxRequestSize=100*1024^2)
  
  data_input <- reactive({ #wraps following expression as reactive, meaning result changes over time
    req(input$csv_input)#req ensures there is csv input, otherwise does not run
    fread(input$csv_input$datapath)#fast reads input$csv$data path, which is file pathway
  })
  
  data_input_long <- reactive({
    pivot_longer(setDF(data_input()), cols = -y, names_to = "Tag", values_to = "Values")
  })
  
  data_filtered <- eventReactive(input$run_button,{
    filter(data_input_long(), Tag %in% input$y_axis)
  })
  
  observeEvent(data_input(),{#wraps code and allows it to run when specific reactive expression changes
    choices <- c(not_sel,names(data_input()))#create variable "choices", with not_sel at top and the names of data table next
    updateSelectInput(inputId = "x_axis", choices = choices)#updates the selectinput, which in turn changes the choices
    updateSelectInput(inputId = "y_axis", choices = choices)
  })
  
  output$plot_1 <- renderPlot({
    ggplot(data_filtered(), aes(x = .data[[input$x_axis]], y = Values, color = Tag))+
      geom_point()
  }) #assigns renderPlot to output, renders graph for plot_1
}

shinyApp(ui = ui, server = server)#creates Shiny application, user interface is layout of app, server is connection between input and output

New contributor

NCcodes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật