gpt4 book ai didi

javascript - 列出包装 Shiny 传单的输入处理程序

转载 作者:行者123 更新时间:2023-11-29 23:23:51 25 4
gpt4 key购买 nike

一般来说,是否有查找包的输入处理程序的函数?传单有几个特殊的输入处理程序,例如input$mymap_shape_mouseover 没有在 R 文档中的任何地方列出。真的,我只是希望能够获取我与传单一起使用的平面 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")
})

最佳答案

发现传单输入事件

对于那些对 leaflet input 事件感兴趣的人 - 例如 input$MAPID_center - 请感谢@blondclover .他们推荐了一个漂亮的技巧来打印出所有 input 事件:

  1. 使用 verbatimTextOutput 在 UI 中创建 output$outputID;和
  2. renderPrint({reactiveValuesToList(input)}) 的结果存储在服务器的 output$outputID 对象中。

随着传单 map 的复杂性增加,了解哪些传单输入事件可用将有助于您自定义 map 。

SS of Leaflet Input Events

# 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com