我和R和Shinyapps在这里遇到了一个非常奇怪的问题。问题是,当我在RStudio中运行应用程序时,一切正常,但是当我在Shinyapps.io上发布它时,我在一些“textOutput”对象上出现以下错误:
错误:无效的'次'参数
对我来说没有意义,但是嘿,可能有原因!
我在这里分享我的完整代码。这是一个在R上使用ggmap,dplyr和shinyapp库的“中途计算器”。
对于ui.R文件,我有:
library(shiny)
shinyUI(fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(h2("Menu"),
br(),
fluidRow(column(12,
textInput("from", label = h4("From"),
value = "Unicentro, Bogotá"))),
fluidRow(column(12,
textInput("to", label = h4("To"),
value = "Calle 116 #20-50, Bogotá"))),
fluidRow(
column(6,
selectInput("mode", label = h5("Mode"),
choices = list("Walking" = "walking",
"Driving" = "driving",
"Transit" = "transit",
"Bike" = "bicycling"
), selected = 1)),
column(6,
numericInput("zoom",
label = h5("Zoom"),
value = 15))),
br(),
fluidRow(column(12,submitButton("Calculate Halfway Point"),align="center"))
),
mainPanel(h1("Halfway Point Map"),
p("NOTE: Wait a couple of second while we make the calculations and plot your map..."),
p("For correct result, the ZOOM scale must be accurate (contain both, the from and to places)"),
plotOutput("map",width=530, height=500),
h3("Halfway Exact Address"),
textOutput("dir"),
h4("Details of trayectory"),
tableOutput("tray")
)
)
))
对于server.R文件:
library(ggmap)
library(dplyr)
shinyServer(function(input, output) {
output$map <- renderPlot({
ggmap(get_map(geocode(c(input$from,input$to)), zoom = input$zoom, maptype='roadmap', source='google', color='color'))+
geom_segment(
aes(x = startLon, y = startLat, xend = endLon, yend = endLat),
colour ="red", size = 1, data = route(input$from, input$to, mode=input$mode)) +
geom_point(aes(x = halfLon, y = halfLat),
data = route(input$from, input$to, mode=input$mode) %>% mutate(cum.m = cumsum(m)) %>%
filter(cum.m >= sum(route(input$from, input$to, mode=input$mode)[1])/2) %>%
top_n(-1,cum.m) %>%
mutate(halfLon = startLon+(endLon-startLon)*(1-(cum.m-sum(route(input$from, input$to, mode=input$mode)[1])/2)/m),
halfLat = startLat+(endLat-startLat)*(1-(cum.m-sum(route(input$from, input$to, mode=input$mode)[1])/2)/m)) %>%
select(halfLon,halfLat),
colour = "black", size = 3)
})
output$dir <- renderText({
paste(
revgeocode(c(
as.numeric(route(input$from, input$to, mode=input$mode) %>% mutate(cum.m = cumsum(m)) %>%
filter(cum.m >= sum(route(input$from, input$to, mode=input$mode)[1])/2) %>%
top_n(-1,cum.m) %>%
mutate(halfLon = startLon+(endLon-startLon)*(1-(cum.m-sum(route(input$from, input$to, mode=input$mode)[1])/2)/m),
halfLat = startLat+(endLat-startLat)*(1-(cum.m-sum(route(input$from, input$to, mode=input$mode)[1])/2)/m)) %>%
select(halfLon)),
as.numeric(route(input$from, input$to, mode=input$mode) %>% mutate(cum.m = cumsum(m)) %>%
filter(cum.m >= sum(route(input$from, input$to, mode=input$mode)[1])/2) %>%
top_n(-1,cum.m) %>%
mutate(halfLon = startLon+(endLon-startLon)*(1-(cum.m-sum(route(input$from, input$to, mode=input$mode)[1])/2)/m),
halfLat = startLat+(endLat-startLat)*(1-(cum.m-sum(route(input$from, input$to, mode=input$mode)[1])/2)/m)) %>%
select(halfLat))),
output="address"),
" | ",
sum(route(input$from, input$to, mode=input$mode)[1])/2,
"m", sep="")
})
output$tray <- renderTable({
route(input$from, input$to, mode=input$mode) %>%
select(-startLon,-startLat,-endLon,-endLat) %>%
mutate(cum.m = cumsum(m))
})
})
我附上了几张截图(右(R)和左(Shinyapps.io))
链接:https://laresbernardo.shinyapps.io/halfway_point_map/
希望你能帮助我,因为这让我疯了!感谢。