通常,是否有一个函数可以找到包的输入处理程序?宣传单有几种特殊的输入处理程序,例如R文档中未列出的input $ mymap_shape_mouseover。确实,我只想能够获取与传单一起使用的平面png热图的坐标,然后将其重新格式化以获取先前绘制的矩阵中的坐标。
library(shiny)
library(leaflet)
library(leaflet.extras)
library(mapview)
library(foreach)
server <- function(input, output, session) {
points <- eventReactive(input$recalc, {
cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
}, ignoreNULL = FALSE)
output$mymap <- renderLeaflet({
bounds <- c(0, 0, 14400, 14400)
leaflet(options = leafletOptions(
crs = leafletCRS(crsClass = "L.CRS.Simple"),
minZoom = -5,
maxZoom = 5)) %>%
fitBounds(bounds[1], bounds[2], bounds[3], bounds[4]) %>%
htmlwidgets::onRender("
function(el, t) {
var myMap = this;
var bounds = myMap.getBounds();
var image = new L.ImageOverlay(
'https://github.com/theaidenlab/juicebox/wiki/images/domains_peaks.png',
bounds);
image.addTo(myMap);
}") %>%
addMeasure() %>%
addMiniMap( toggleDisplay = TRUE,
position = "bottomleft") %>% addDrawToolbar() %>% addFullscreenControl() %>%
addMouseCoordinates(style="basic")
})
最佳答案
发现传单输入事件
对于那些对传单input
事件(例如input$MAPID_center
)感兴趣的人,请感谢@blondclover。他们推荐了一个巧妙的技巧来打印出所有input
事件:
使用output$outputID
在UI中创建verbatimTextOutput
;和
将renderPrint({reactiveValuesToList(input)})
的结果存储在服务器的output$outputID
对象中。
随着传单地图的复杂性增加,了解哪些传单输入事件可供使用将有助于您自定义地图。
# load necessary packages
library( shiny )
library( leaflet )
library( mapview )
ui <- fluidPage(
leafletOutput( outputId = "map"),
downloadButton( outputId = "dl"),
h2("List of Input Events"),
verbatimTextOutput( outputId = "text")
)
server <- function(input, output, session) {
# print list of input events
output$text <-
renderPrint({reactiveValuesToList(input)})
# Create foundational leaflet map
# and store it as a reactive expression
foundational.map <- reactive({
leaflet() %>% # create a leaflet map widget
addTiles( urlTemplate = "https://{s}.tile.openstreetmap.se/hydda/base/{z}/{x}/{y}.png" ) # specify provider tile and type
}) # end of foundational.map()
# render foundational leaflet map
output$map <- leaflet::renderLeaflet({
# call reactive map
foundational.map()
}) # end of render leaflet
# store the current user-created version
# of the Leaflet map for download in
# a reactive expression
user.created.map <- reactive({
# call the foundational Leaflet map
foundational.map() %>%
# store the view based on UI
setView( lng = input$map_center$lng
, lat = input$map_center$lat
, zoom = input$map_zoom
)
}) # end of creating user.created.map()
# create the output file name
# and specify how the download button will take
# a screenshot - using the mapview::mapshot() function
# and save as a PDF
output$dl <- downloadHandler(
filename = paste0( Sys.Date()
, "_customLeafletmap"
, ".pdf"
)
, content = function(file) {
mapshot( x = user.created.map()
, file = file
, cliprect = "viewport" # the clipping rectangle matches the height & width from the viewing port
, selfcontained = FALSE # when this was not specified, the function for produced a PDF of two pages: one of the leaflet map, the other a blank page.
)
} # end of content() function
) # end of downloadHandler() function
} # end of server
# run the Shiny app
shinyApp(ui = ui, server = server)
# end of script #
关于javascript - 列出包装 Shiny 传单的输入处理程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49885751/