I found the answers I needed using these two instructions together:
https://docs.ropensci.org/rtweet/articles/auth.html#save
How to pass environment variables to shinyapps
This allowed me to publish the app to shinyapps.io without hardcoding any secret information into the app. Instead I used the functions rtweet::rtweet_app
and rtweet::auth_app
like this at the top of the server.R file:
app <- rtweet::rtweet_app(bearer_token = Sys.getenv("MY_BEARER_TOKEN"))
rtweet::auth_as(app)
The part saying Sys.getenv("MY_BEARER_TOKEN")
retrieves the token from an environmental variable that you store according to recipe 2 above (the bearer token that you need to put in that .Renviron file is gotten from the Twitter developer platform and your app project there). The only thing to note regarding the recipe in link 2 above is that you should not store the .Renviron file locally at your computer but in the app that you publish to shinyapps.io, (as commented by the user Erik Iverson: "This worked for me after creating a copy of my .Renviron file in the root directory of my Shiny application").