问题描述
一般来说,是否有找到包的输入处理程序的功能?传单有几种特殊的输入处理程序,例如:输入$ mymap_shape_mouseover,它们不在R文档中列出。真的,我只是希望能够抓住我正在使用传单的平面png热图的坐标,并重新格式化它们以获取我之前绘制的矩阵中的坐标。
库(闪亮)
库(传单)
库(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)
输出$ mymap< - renderLeaflet({
bounds< - c(0 ,0,14400,14400)
宣传单(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_p eaks.png',
bounds);
image.addTo(myMap);
})%>%
addMeasure()%>%
addMiniMap(toggleDisplay = TRUE,
position =bottomleft)%>%addDrawToolbar()% >%addFullscreenControl()%>%
addMouseCoordinates(style =basic)
})
发现传单输入事件
对于那些对传单输入感兴趣的人
事件 - 例如输入$ MAPID_center
- 请感谢
#load必要包
库(有光泽)
库(传单)
库(mapview)
ui< - fluidPage(
leafletOutput(outputId =map),
downloadButton(outputId =dl),
h2(输入列表事件),
verbatimTextOutput(outputId =text)
)
服务器< - 函数(输入,输出,会话){
#print输入事件列表
输出$ text< -
renderPrint({reactiveValuesToList(input)})
#创建基础传单映射
#并存储它作为反应式表达式
foundational.map< - 被动({
传单()%>%#创建传单地图小部件
a ddTiles(urlTemplate =https:// {s} .tile.openstreetmap.se / hydda / base / {z} / {x} / {y} .png)#指定提供者磁贴并键入
})#endational.map()
#render基础传单
输出$ map< - leaflet :: renderLeaflet({
# call reactive map
foundational.map()
})#end of render leaflet
#存储当前用户创建的版本
#of the小册子地图下载
#a反应表达式
user.created.map< - 被动({
#调用基础传单地图
foundational.map( )%>%
#存储基于UI的视图
setView(lng =输入$ map_center $ lng
,lat =输入$ map_center $ lat
, zoom = input $ map_zoom
)
})#end创建user.created.map()
#创建输出文件名
#并指定下载按钮将如何获取
#cree nshot - 使用mapview :: mapshot()函数
#并保存为PDF
输出$ dl< - downloadHandler(
filename = paste0(Sys.Date()
,_ customeafletmap
,。pdf
)
,content = function(file){
mapshot(x = user.created.map()
,file = file
,cliprect =viewport#剪裁矩形匹配高度&从观察端口宽度
,selfcontained = FALSE#当未指定时,该函数用于生成两页PDF:一个是传单地图,另一个是空白页面。
)
}#end of content()函数
)#outnd ofHandler()函数
} #cnd of server
#运行Shiny app
shinyApp(ui = ui,server = server)
#脚本结束#
Is there a function to find the input handlers for a package, generally? There are several special input handlers for leaflet, e.g. input$mymap_shape_mouseover that are not anywhere listed in the R documentation. Really, I just want to be able to grab the coordinates of a flat png heatmap that I'm using with leaflet and reformat them to grab the coordinates in the matrix I've previously plotted.
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")
})
Discovering Leaflet Input Events
For those interested in leaflet input
events - such as input$MAPID_center
- please thank @blondclover. They recommended a nifty trick to print out all input
events:
- Create the
output$outputID
in the UI usingverbatimTextOutput
; and - Store the results of
renderPrint({reactiveValuesToList(input)})
in theoutput$outputID
object in server.
As the complexity of your leaflet map grows, knowing which leaflet input events are available to use will help you customize your map.
# 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 #
这篇关于列出包装闪亮传单的输入处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!