Problem when deploying my shiny app:
library(shiny)
library(plotly)
ui_inc <- fluidPage(
plotlyOutput("graph"),
sliderInput("slider", "Average income: ", min = 65000, max = 75000, step = 2500, value = 70000)
)
server_inc <- function(input, output) {
inc_values <- seq(65000, 75000, by = 2500)
y_range <- c(0, get_density(0, inc, 700, get_u(inc, 700,2000000)))
output$graph <- renderPlotly({
fig <- plot_ly(type = 'scatter', mode = 'lines', showlegend = FALSE)
annotations <- list() # Initialize empty list for annotations
for (i in seq_along(inc_values)) {
inc_value <- inc_values[i]
u <- get_u(inc_value, t, 2000000)
title_text <- paste("Urban Density")
border_value <- get_border(target_border, inc_value, t, u) # Calculate border value
fig <- fig %>%
add_trace(
x = seq(0, border_value, by = 0.1),
y = get_density(seq(0, border_value, by = 0.1), inc_value, t, u),
visible = (inc_value == input$slider),
line = list(color = 'grey'))
# Add vertical line segment for each trace
fig <- fig %>%
add_segments(
x = c(border_value, border_value),
y = c(0, 20000),
xend = c(border_value, border_value),
yend = c(20000, 20000), # Change yend value to 20000
visible = (inc_value == input$slider),
line = list(color = 'grey', dash = 'dash')) # Set the line dash to 'dot'
# Create annotation for each slider value
annotation <- list(
x = border_value*0.99,
y = 10000, # Adjust the y-coordinate of the label
xref = 'x',
yref = 'y',
text = paste("City boundary: ", round(border_value, 1), " km"),
showarrow = TRUE,
arrowhead = 2,
ax = -100,
ay = 0
)
if (inc_value == input$slider) {
annotations <- c(annotations, list(annotation))
}
}
fig <- fig %>%
layout(
title = title_text,
xaxis = list(range = c(0, 50), title = "distance from central business district"),
yaxis = list(range = y_range, title = "population density - people/sqkm"),
annotations = annotations # Add the annotations to the layout
)
})
}
rsconnect::deployApp('path')
Error:
── Preparing for deployment ───────────────────────────────────────────────────────────────────────────────────
✔ Deploying "repository-name" to "server: shinyapps.io / username: pz0qty-user-name"
Error in yaml::yaml.load(yamlData) :
Scanner error: mapping values are not allowed in this context at line 4, column 30