I've been reading other people having similar issues when deploying shinyapp to https://www.shinyapps.io
The common issue appears to be the used packages by the app, and the solution is to install them from CRAN instead of Github. I've done this but without success.
I'm thinking it's because I'm using the leaflet package to show a map. It was a little difficult to have it running locally and maybe it's more difficult for https://www.shinyapps.io to deploy it?
This is my APP, maybe someone could help me out:
ui.R:
library(shiny)
library(shinydashboard)
library(plotly)
library(formattable)
library(DT)
library(leaflet)
library(plotly)
header <- dashboardHeader(title = 'LaCuracao.pe Dashboard',
tags$li(class = "dropdown",
tags$a(href="https://lacuracao.pe/", target="_blank",
tags$img(height = "22px", alt="La Curcao Perú", src="lc-logo.png")
)
)
)
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Ventas", tabName = "Ventas", icon = icon("th"),
badgeLabel = "new", badgeColor = "green"),
menuItem("ga", tabName = "ga", icon = icon("th"),
badgeLabel = "new", badgeColor = "green"),
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "resumen",
fluidRow(
box(width = 2, actionButton("count", "Count")),
infoBoxOutput("ibox"),
valueBoxOutput("vbox")
)
),
tabItem(tabName = "dashboard",
dateRangeInput('dateRange',
label = 'Seleccione fechas',
start = '2018-05-01', end = '2018-05-31',
language = 'es', separator = " al "),
column(6
),
DT::dataTableOutput('productos_ingresos'),
br(),
br()
),
tabItem(tabName = "ga",
column(6
),
DT::dataTableOutput('sesiones_por_mes'),
plotlyOutput("plot"),
br()
),
tabItem(tabName = "Ventas",
h2("Ventas Perú"),
#verbatimTextOutput("total_ventas"),
radioButtons("lima_no_lima", "Total departamentos a visualizar:",
inline = TRUE,
choices = c("Considerar Lima" = "considerar_lima",
"No considerar Lima" = "no_considerar_lima")),
dateRangeInput('dateRangeMap',
label = 'Seleccione fechas',
start = '2018-08-01', end = '2018-08-16',
min = "2018-08-01",
max = "2020-08-21",
language = 'es', separator = " al "),
textOutput("total_ventas"),
leafletOutput("mymap"),
br(),
br()
)
)
)
# Put them together into a dashboardPage
dashboardPage(skin = "black",
header,
sidebar,
body
)
server.R
library(shiny)
library(leaflet)
library(dplyr)
library(readr)
library(plotly)
server <- function(input, output, session) { #session is an important argument for server function
peru_ventas <- reactive({
#ventas <- read_csv("www/ventas.csv", skip = 2)
ventas <- read_csv("https://www.dropbox.com/s/ehzwrjnwkwbs06p/ventas.csv?dl=1", skip = 2)
ventas <- ventas[,c("FECHA_PED", "DEPARTAMENTO", "TOTAL_PEDIDO")]
ventas$TOTAL_PEDIDO <- as.numeric(ventas$TOTAL_PEDIDO)
ventas$FECHA_PED <- as.Date(ventas$FECHA_PED, format = "%d/%m/%Y")
ventas$DEPARTAMENTO <- gsub("CALLAO", "LIMA", ventas$DEPARTAMENTO)
dates <- seq(as.Date(input$dateRangeMap[1]), as.Date(input$dateRangeMap[2]), "days")
if(input$lima_no_lima == "considerar_lima") {
print("Se considera Lima")
ventas_departamentos <- ventas %>%
group_by(DEPARTAMENTO) %>%
summarise(VENTAS = sum(TOTAL_PEDIDO * (FECHA_PED %in% dates),
na.rm = TRUE))
} else if(input$lima_no_lima == "no_considerar_lima") {
print("No se considera Lima")
ventas_departamentos <- ventas %>%
group_by(DEPARTAMENTO) %>%
summarise(VENTAS = sum(TOTAL_PEDIDO * (FECHA_PED %in% dates),
na.rm = TRUE)) %>%
mutate(VENTAS = case_when(DEPARTAMENTO == "LIMA" ~ 0,
DEPARTAMENTO != "LIMA" ~ VENTAS))
}
peru <- geojsonio::geojson_read("https://www.dropbox.com/s/j8a0a9jecrcd8a2/peru_sin_callao.geojson?dl=1", what = "sp")
peru$ventas <- ventas_departamentos$VENTAS
peru
})
### Sesiones GA ####
sesiones <- reactive({
sesiones_ga <- read_csv("https://www.dropbox.com/s/gvov9pgaxk125aa/ga-sesiones-lc-20180824.csv?dl=1", skip = 0)
sesiones_ga <- sesiones_ga %>%
group_by(sources) %>%
summarise(sessions = sum(sessions))
})
productos <- reactive({
productos_revenue <- read_csv("https://www.dropbox.com/s/75hmxn79k9zvlgk/ga-productos-lc-20180824.csv?dl=1", skip = 0)
})
output$productos_ingresos <- DT::renderDataTable(
datatable(productos(),
options = list(
order = list(list(3, 'desc')),
language = list(url = '//cdn.datatables.net/plug-ins/1.10.11/i18n/Spanish.json'))) %>% formatCurrency(c('itemRevenue'), currency = ' S/.',
interval = 3, mark = ',', before = TRUE)
)
####
output$sesiones_por_mes <- DT::renderDataTable(
datatable(sesiones())
)
#######
output$plot <- renderPlotly({
plot_ly(sesiones(), x = ~sessions, y = ~sources, type = 'bar', orientation = 'h') %>% #color = I("red")
layout(title = "Sesiones por fuente de tráfico",
xaxis = list(title = ""),
yaxis = list(title = "")) %>%
layout(hovermode = 'compare',
separators = ',')
})
#######
output$total_ventas <- renderText({
paste0("Total ventas: S/.", prettyNum(sum(peru_ventas()$ventas),big.mark=",", preserve.width="none"))
})
output$mymap <- renderLeaflet({
#browser()
peru <- peru_ventas()
pal <- colorBin("YlOrRd", domain = peru$ventas, bins = 5)
labels <- sprintf(
"<strong>%s</strong><br/>S/.%s soles",
peru$NOMBDEP, prettyNum(peru$ventas,big.mark=",", preserve.width="none")
) %>% lapply(htmltools::HTML)
leaflet(peru) %>%
setView(-75, -10, 4) %>%
addProviderTiles("MapBox", options = providerTileOptions(
id = "mapbox.light",
accessToken = Sys.getenv('MAPBOX_ACCESS_TOKEN'))) %>%
addPolygons(
fillColor = ~pal(ventas),
weight = 2,
opacity = 1,
color = "white",
dashArray = "3",
fillOpacity = 0.7,
highlight = highlightOptions(
weight = 3,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto")) %>%
addLegend(pal = pal, values = ~ventas, opacity = 0.7, title = NULL,
position = "bottomright")
})
}