Hello,
I am a new to building shiny apps. I built one (code below) and I was able to successfully publish to shinyapps.io and run it locally. For some reason I wasn't able to use the Publish button in R to publish as I would get in error. Not sure if that is related to the current problem. When I go to open the app online, I get this error: "An error has occurred. The application failed to start. exit status 1" I checked my log and it says "Error in rsconnect:: "my pathway" does not exist." I'm wondering if it is something strongly wrong in my code or something else. Any help is very much appreciated
r
library(shiny)
library(scales)
library(openxlsx)
library(rsconnect)
ui <- fluidPage(
titlePanel("Membership and Revenue Forecasting Tool"),
tags$style(HTML("
body, .shiny-output table th, .shiny-output table td {
color: white; /* Change text color to white */
}
.control-label {
color: black; /* Change input label color to black */
}
.contact-link {
text-align: center; /* Center align the contact link */
margin-top: 20px; /* Add some margin at the top */
}
.irs-grid-text {
color: black !important; /* Change slider numbers color to black */
}
")),
tags$style(HTML("
body {
background-color: #000000; /* Change to your desired color */
}")),
sidebarLayout(
sidebarPanel(
numericInput("members", "Number of Members:", value = 1000),
numericInput("price", "Price of Membership ($):", value = 100),
sliderInput("retention", "Estimated Retention Rate (%):", min = 0, max = 100, value = 90),
sliderInput("growth_rate", "Estimated Growth Rate (%):", min = 0, max = 100, value = 1),
actionButton("simulate", "Simulate"),
downloadButton("download_excel", "Export to Excel")
),
mainPanel(
tags$h3("Projected Outcomes", style = "color: white;"),
tableOutput("results_table")
)
),
div(style = "position: absolute; bottom: 10px; ;left: 10px;",
img(src = "my image", height = 50)),
div(style = "position: absolute; bottom: 10px; right: 10px;",
img(src = "my image address", height = 50)),
# Add contact link
div(class = "contact-link", style = "position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);",
tags$a("Ready to take the next step? Contact Avenue M", href = "my website"))
)
server <- function(input, output) {
observeEvent(input$simulate, {
members <- input$members
price <- input$price
retention <- input$retention / 100
growth_rate <- input$growth_rate / 100
years <- 3
revenue <- numeric(years)
membership <- numeric(years)
# Calculate revenue and membership for "Current" row
revenue[1] <- members * price
membership[1] <- members
# Calculate revenue and membership for subsequent years
for (year in 2:years) {
members <- members * retention * (1 + growth_rate)
price <- price * (1 + growth_rate)
revenue[year] <- members * price
membership[year] <- members
}
# Calculate values for year 3
members_year_3 <- members * retention * (1 + growth_rate)
price_year_3 <- price * (1 + growth_rate)
revenue_year_3 <- members_year_3 * price_year_3
# Append year 3 values to the results data frame
results <- data.frame(
Year = c("Current", 1:3),
Revenue = c(dollar(revenue[1], prefix = "$"), dollar(revenue[2:3], prefix = "$"), dollar(revenue_year_3, prefix = "$")),
Membership = c(scales::comma(membership[1], big.mark = ","), scales::comma(membership[2:3], big.mark = ","), scales::comma(members_year_3, big.mark = ","))
)
output$results_table <- renderTable({
results
})
output$download_excel <- downloadHandler(
filename = function() {
paste("membership_revenue_forecast.xlsx", sep = "")
},
content = function(file) {
input_data <- data.frame(
"Input" = c("Number of Members", "Initial Membership Price ($)", "Estimated Retention Rate (%)", "Estimated Growth Rate (%)"),
"Input Value" = c(input$members, input$price, input$retention, input$growth_rate)
)
write.xlsx(cbind(input_data, results), file)
}
)
})
}
shinyApp(ui = ui, server = server)```