2017-01-31 27 views
0

Я пытаюсь разбить мое блестящее приложение на хостинг на shinyapps.io, но когда я разложил приложение, я потерял данные.Неисправность при расщеплении приложения Shiny Leaflet

Когда ui и сервер вместе, он работает; но разделяя их на два отдельных файла, я теряю боковую панель.

ui.R

library(shiny) 
library(leaflet) 
library(RColorBrewer) 
library(shiny) 

shinyUI(
    bootstrapPage(
    tags$style(type = "text/css", "html, body {width:100%;height:100%}"), 
    leafletOutput("map", width = "100%", height = "100%"), 
    absolutePanel(uiOutput("sorted.data"), top = 10, right = 10 
       ) 
    ) 
) 

и

server.r 

library(shiny) 
library(leaflet) 
library(RColorBrewer) 
library(maps) 

capwords <- function(s, strict = FALSE) { 
    cap <- function(s) paste(toupper(substring(s, 1, 1)), 
          {s <- substring(s, 2); if(strict) tolower(s) else s}, 
          sep = "", collapse = " ") 
    sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s))) 
} 

# mapStates = map("state", fill = TRUE) 
# data("us.cities") 
map.cities(us.cities) 
# leaflet(mapStates) %>% addTiles() %>% setView(lng = -97.00, lat = 38.00, zoom = 4) 

# import and clean data 
alumni <- read.csv("../Residency Match List 2010-2015 - Sheet1.csv", stringsAsFactors = F, header = T) 
# convert city to lowercase then capitalize it, then paste it together with the state 
# we're doing this to match the alumni data to the us.cities data 
alumni$city.state <- paste(capwords(tolower(alumni$City)), alumni$State) 

# merge the data by the city.state column we just created and the name column in the us.cities data 
alumni.map.data <- merge(alumni, us.cities, by.x = "city.state", by.y = "name") 

shinyServer(function(input, output, session) { 

    # Reactive expression for the data subsetted to what the user selected 
    filteredData <- reactive({ 
     alumni.map.data[alumni.map.data$Primary.Specialty == input$Primary.Specialty,] 
    }) 

    output$sorted.data <- renderUI({sort(unique(alumni.map.data$Primary.Specialty))}) 

    output$map <- renderLeaflet({ 
     # Use leaflet() here, and only include aspects of the map that 
     # won't need to change dynamically (at least, not unless the 
     # entire map is being torn down and recreated). 
     leaflet(alumni.map.data) %>% addTiles() %>% 
     fitBounds(~min(long), ~min(lat), ~max(long), ~max(lat)) 
    }) 

    # Incremental changes to the map (in this case, replacing the 
    # circles when a new color is chosen) should be performed in 
    # an observer. Each independent set of things that can change 
    # should be managed in its own observer. 
    observe({ 

     leafletProxy("map", data = filteredData()) %>% 
     clearMarkers() %>% clearMarkerClusters() %>% 
     addCircleMarkers(
      popup = ~as.character(paste(sep = "<br/>", 
             paste0('<a href = ', #begin link format to search google 
              "https://www.google.com/#q=", 
              paste(First.Name, 
                Last.Name, "Tulane", sep = "+"), #search elements 
              ">", 
              paste(First.Name, Last.Name, sep = " "), 
              '</a>'), # end link format to search google 
             paste("Class of", Class.Year, sep = " "),Program, 
             Primary.Specialty)), 
      clusterOptions = markerClusterOptions() 
     ) 
    }) 
    }) 

Когда я запускаю этот код карты визуализируется, но без какой-либо из кластеров/маркеров, и я получаю следующее сообщение об ошибке:

Warning in charToRaw(enc2utf8(text)) : 
    argument should be a character vector of length 1 
all but the first element will be ignored 
Assuming 'long' and 'lat' are longitude and latitude, respectively 

Я чувствую, что мне не хватает чего-то простого. Спасибо!

ответ

0

Я не 100% на это, потому что я не могу воссоздать так что я угадал, но я бы все, что это находится в файле server.r перед строкой

shinyServer(function(input, output, session){ 

и положить его в файл global.r в том же каталоге.

То же самое относится ко всем библиотечным вызовам, просто имейте их всех в global.r