如何在关闭屏幕的智能手机上继续运行闪亮的移动应用程序?

时间:2021-01-09 20:49:33

标签: r shiny leaflet shinyapps screen-off

我正在运行一个 ShinyMobile 应用程序(在 Android 智能手机上,使用内部浏览器,在shinyapps.io 上运行),使用leaflet.extras 包来检索GPS 位置数据。只要屏幕开启,就可以正常工作。

当屏幕关闭时,不会检查其他位置。

当我再次打开屏幕时,进程继续运行,没有问题。

有没有办法在屏幕关闭的情况下继续监控 GPS 位置?

代码:

library(leaflet)
library(leaflet.extras)
library(shiny)
library(shinyMobile)

ui <- f7Page(
  title = "Tracker",
  f7SingleLayout(
    navbar = f7Navbar(title = "Tracker"),
    leafletOutput('map'),
    tableOutput("table")
  ) 
) 

server <- function(input, output, session) {

  # track df creation
  track <- reactiveValues(pos=data.frame(matrix(ncol = 3,
                                                nrow = 0)),count =1)
  # creating df for a single point  
   newpos <- reactive({
     data.frame(
       id = track$count,
       lon = input$map_gps_located$coordinates$lng,
       lat = input$map_gps_located$coordinates$lat)
   }) 
   
   # adding a point to the track
   storedValues <- observeEvent(input$map_gps_located$coordinates, {
     track$pos <- rbind(track$pos, newpos())
     track$count <- track$count +1
   })
 
   # track
   output$table <- renderTable({track$pos})
     
   #plotting the map
   output$map <- renderLeaflet({ 
    leaflet()%>%
    addTiles() %>% 
    addControlGPS(options = gpsOptions(position = "topleft", activate = TRUE, 
                                         autoCenter = TRUE, maxZoom = 60, 
                                         setView = TRUE))
    })
 
}

shinyApp(ui, server)

0 个答案:

没有答案