小编Dhi*_*raj的帖子

在R中导入python模块

我正在尝试使用reticulate包导入R中的python模块.该模块可以在这里找到.我克隆了存储库并python setup.py install运行成功运行.如果我打开python shell,我就可以导入了debot.但是,当我尝试在RStudio中导入它时,我收到以下错误:

dbot=import("debot")
Error in py_module_import(module, convert = convert) : 
  ImportError: No module named debot
Run Code Online (Sandbox Code Playgroud)

我在macOS Sierra版本10.12.6上,并通过Anaconda安装了python 3.6.我也试过给python的路径:

path_to_python <- "/anaconda/bin/python3.6"
use_python(path_to_python)
Run Code Online (Sandbox Code Playgroud)

当我从终端运行python时,我得到:

Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Run Code Online (Sandbox Code Playgroud)

不确定python的路径是否正确.

好吧,做了一些更多的挖掘,并发现reticulate仍然引用我的旧版python路径为python 2.7,默认情况下我的Macbook.当我跑步时py_config(),这就是我得到的:

python:         /usr/bin/python
libpython:      /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome:     /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version:        2.7.10 (default, Feb  7 2017, …
Run Code Online (Sandbox Code Playgroud)

python r reticulate

6
推荐指数
1
解决办法
4747
查看次数

在传单中绘制 sfc_POLYGON

我有一个 sfc_POLYGON,IHS使用sf包作为几个形状的联合获得。

Geometry set for 1 feature 
geometry type:  POLYGON
dimension:      XY
bbox:           xmin: 270194.7 ymin: 2255850 xmax: 279225 ymax: 2265469
epsg (SRID):    32643
proj4string:    +proj=utm +zone=43 +datum=WGS84 +units=m +no_defs
POLYGON((279224.998943279 2261084.1514869, 2792...
Run Code Online (Sandbox Code Playgroud)

虽然我能够mapviewleaflet. 当我绘制 this is 时leaflet,我收到一个警告sf layer is not long-lat data,但它不是,我得到了基本世界地图。这是我用于在leaflet.

IHS%>%leaflet()%>%addTiles()%>%
  addProviderTiles(providers$Esri.WorldImagery, group ="ESRI")%>%
  addPolygons()
Run Code Online (Sandbox Code Playgroud)

我怀疑这与 CRS 有关系。我试过st_set_crs(IHS, 4326)将我的投影IHS从 utm更改为 longlat:

Geometry set for 1 feature 
geometry type:  POLYGON …
Run Code Online (Sandbox Code Playgroud)

r leaflet r-sf

5
推荐指数
1
解决办法
2088
查看次数

R传单情节船方向

我有关于船只/船只的位置以及它们所转向的路线的信息。我想将它们绘制在带有看起来像船的自定义图标的传单地图上。我发现"tags"图标 fromglyphicons是最合适的。这里有一些数据可以玩:

dput(head(x))
structure(list(boatName = c("Conti Benguela", "Sunny Bay", "Sunny Horizon", 
"FMT URLA", "Qi Xiang 22", "STI Solidarity"), lat = c(37.115365, 
38.4772017, 14.632, 56.80515, 51.31172, -2.2783283), lon = c(15.2682183, 
-8.7888783, -79.5806667, 7.601885, -143.5678933, 46.6328383), 
    cog = c("16", "331", "182", "21", "288", "72")), row.names = c(NA, 
6L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)

cog指示地面上的路线,图标转换为旋转角度。我正在使用以下代码当前绘制船只的位置和根据船只转向的路线旋转:

shipIcon <- makeAwesomeIcon("tag",iconRotate = x$cog)
leaflet() %>% addTiles() %>% 
  addAwesomeMarkers(lng=x$lon,lat=x$lat,icon=shipIcon,popup = x$boatName)
Run Code Online (Sandbox Code Playgroud)

但是,如您所见,makeAwesomeIcon为我不想要的图标添加了一个背景标记。我已经看过thisthis,后者正是我想要做的。我怎样才能完成我的任务,即根据它在没有标记背景的情况下转向的路线显示带有旋转的自定义船舶图标?

r leaflet htmlwidgets htmltools

3
推荐指数
1
解决办法
1764
查看次数

在Shiny App中重置fileInput

我一直试图fileInput在Shiny应用程序中重置并阅读类似问题的解决方案,但我的问题仍然存在.大多数解决方案最终导致使用Dean Attali的精彩shinyjs包装及其中的reset()功能.以下是遵循以下说明后我的代码的样子:

library(shiny)
library(shinyjs) 
library(xlsx) 
library(tidyverse) 

ui <- fluidPage(
  useShinyjs(),
  fileInput('inFile', 'Choose file'),
  actionButton('reset', 'Reset'),
  radioButtons("type","Choose file type",choices = c('csv','xls')),
  tableOutput('tbl')
)

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

  rv <- reactiveValues(data = NULL)

  observe({
    req(input$inFile)
    if(input$type=='csv'){
      rv$data <- read.csv(input$inFile$datapath)
    }
    if(input$type=='xls'){
      rv$data <- read_excel(input$inFile$datapath)
    }

  })

  observeEvent(input$reset, {
    rv$data <- NULL
    reset('inFile')
  })

  output$tbl <- renderTable({
    rv$data
  })
}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

我最初选择该csv选项,并能够加载csv文件.现在当我按下重置按钮时,它会清除数据.一旦我选择该xls选项,我就会收到错误:

Listening on http://127.0.0.1:4135
Warning: Error in …
Run Code Online (Sandbox Code Playgroud)

r shiny shinyjs

2
推荐指数
1
解决办法
855
查看次数

标签 统计

r ×4

leaflet ×2

htmltools ×1

htmlwidgets ×1

python ×1

r-sf ×1

reticulate ×1

shiny ×1

shinyjs ×1