df[,1] <- as.factor(df[,1]) works in regular environment, but not in shiny environment.

this is an issue regarding the differences between data.frames and tibbles and is not shiny related.

Here is some background reference: Tibbles.

Here is a brief example script I made for you .

library(tidyverse)

 t1 <- tibble(a=1:2,
        l=letters[1:2])
 
 d1 <- as.data.frame(t1)
 

 d1[,1]
 t1[,1]
 
d1[,1] <- 3:4 #fine 
t1[,1] <- 3:4 #fine

d1[,1]
t1[,1]

d1[,1] <- d1[,1] #fine 
t1[,1] <- t1[,1] #fine

d1[,1] <- as.factor(d1[,1])
t1[,1] <- as.factor(t1[,1]) # your problem ; and 'breaks t1'
t1

(t1 <-  t1 <- tibble(a=3:4,
                     l=letters[1:2])) # remaking 

t1[[1]] <- as.factor(t1[[1]]) # achieves the required and works 

# another option is mutating a tibble in the dplyr way
t1 <- mutate(t1,
             across(1,as.factor))
t1