Hi there,
I seem to be having a "paths should point to files within the project directory" issue. I'm able to correctly run a shiny app locally on my computer from my code, but when I go to "Publish" it, an error is generated.
I'm trying to create my fist shiny app from a csv file I saved in my shiny_ex folder, the same one that holds the app.R file I'm trying to publish. I thought having the csv file and the app.R file in the same folder is what it means to have "paths should point to files within the project directory". The warning sign is given when I load in country_2018.csv.
ChatGPT recommended I create a relative path but that didn't work either.
My code is:
#library(shiny)
#library(dplyr)
#library(readr)
country_2018 <- read_csv('/Users/jackconnors/shiny/shiny_ex/country_2018.csv')
ui <- fluidPage(
titlePanel("Share of People at Levels 1-5 by Country"),
sidebarLayout(
sidebarPanel(
selectInput("country", "Select Country:", choices = unique(country_2018$name)),
width = 3), mainPanel(plotOutput("levelPlot"))))
# Define server logic
server <- function(input, output) {
# Filter data based on selected country
selected_country <- reactive({
country_2018 %>%
filter(name == input$country)})
# Create a bar plot for share of people at levels 1-5
output$levelPlot <- renderPlot({
req(input$country)
selected_country_data <- selected_country()
levels_data <- selected_country_data %>%
select(Share.of.people.on.Level.1:Share.of.people.on.Level.5)
# Create a matrix for each level
level1 <- levels_data$Share.of.people.on.Level.1
level2 <- levels_data$Share.of.people.on.Level.2
level3 <- levels_data$Share.of.people.on.Level.3
level4 <-levels_data$Share.of.people.on.Level.4
level5 <-levels_data$Share.of.people.on.Level.5
# Stack the matrices together
bar_data <- rbind(level1, level2, level3, level4, level5)
barplot(bar_data,
beside = TRUE, # Stacked bars
col = rainbow(5),
ylim = c(0, 1),
main = paste("Share of People at Levels 1-5 in", input$country),
xlab = "Levels",
ylab = "Share",
legend.text = colnames(levels_data),
args.legend = list(x = "topright"))})}
# Run the Shiny App
shinyApp(ui = ui, server = server)
Any help would be much appreciated! This is my first shiny app and I'm trying to link it to my website