2017-01-31 42 views
0

我想分裂我的Shiny應用程序上主機shinyapps.io,但是當我分開的應用程序,我失去了數據。麻煩當分裂閃亮的單張應用程序

當用戶界面和服務器在一起,它的工作原理;但是將它們分成兩個單獨的文件,我就失去了側邊欄​​。

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文件中。

同樣適用於所有圖書館的電話,只需全部在全球使用.r