Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 闪亮服务器:Leavet不';t在图例中显示绿色_R_Ubuntu_Shiny_Leaflet_Viridis - Fatal编程技术网

R 闪亮服务器:Leavet不';t在图例中显示绿色

R 闪亮服务器:Leavet不';t在图例中显示绿色,r,ubuntu,shiny,leaflet,viridis,R,Ubuntu,Shiny,Leaflet,Viridis,我在使用viridis调色板绘制图例的颜色时遇到问题:虽然图例标签已显示,但颜色不会显示 我在Ubuntu下用Shining Server v1.4.2.786用Node.js v0.10.40(不显示绿色)和MacOS下测试了相同的代码(正确显示) Ubuntu R会话的详细信息: R version 3.3.1 (2016-06-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 15.10 leaflet_1

我在使用viridis调色板绘制图例的颜色时遇到问题:虽然图例标签已显示,但颜色不会显示

我在Ubuntu下用
Shining Server v1.4.2.786
Node.js v0.10.40
(不显示绿色)和MacOS下测试了相同的代码(正确显示)

Ubuntu R会话的详细信息:

R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 15.10

leaflet_1.0.1 shiny_0.13.2  viridis_0.3.4
这是不显示颜色的图例

    leaflet() %>% addTiles() %>% addLegend(
      position = 'bottomright',
      colors = viridis(8), 
      labels = viridis(8), opacity = 1)
而这也适用于Ubuntu机器

    leaflet() %>% addTiles() %>% addLegend(
      position = 'bottomright',
      colors = rgb(t(col2rgb(palette())) / 255), 
      labels = palette(), opacity = 1)

这似乎真的是viridis调色板的颜色代码的问题(我尝试将它们复制/粘贴到字符向量中)

一个有效的例子

library(shiny)
library(leaflet)
library(viridis)

r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()

ui <- fluidPage(
  leafletOutput("mymap")
)

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

  output$mymap <- renderLeaflet({
    leaflet() %>% addTiles() %>% addLegend(
      position = 'bottomright',
      colors = viridis(8), 
      labels = viridis(8), opacity = 1)

  })
}

shinyApp(ui, server)
库(闪亮)
图书馆(单张)
图书馆(绿色)

我正在运行一台Ubuntu机器14.04LTS。我能够获得图例上的颜色,但是看起来颜色没有列在colors()函数中,并且图例的标签仍然是十六进制代码

这部分代码应检索颜色名称:

colors()[match(rgb(t(col2rgb(leafletColors)), 
                       maxColorValue = 255), c(rgb(t(col2rgb(colors())), maxColorValue = 255)))]
修改后的app.R代码

    library(shiny)
    library(leaflet)
    library(viridis)

    r_colors <- rgb(t(col2rgb(colors()) / 255))
    names(r_colors) <- colors()
    leafletColors <- palette(viridis(8))

    ui <- fluidPage(
            leafletOutput("mymap"),
            p(),
            actionButton("recalc", "New points")
    )

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

            points <- eventReactive(input$recalc, {
                    cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
            }, ignoreNULL = FALSE)

            output$mymap <- renderLeaflet({
                    leaflet() %>%
                            addProviderTiles("Stamen.TonerLite",
                                             options = providerTileOptions(noWrap = TRUE)
                            ) %>%
                            addMarkers(data = points()) %>% 
                            addLegend(
                                    position = 'bottomright',
                                    colors = leafletColors, 
                                    labels = palette(), opacity = 1)
            })
    }

    shinyApp(ui, server)
库(闪亮)
图书馆(单张)
图书馆(绿色)

r_颜色这与
viridis
调色板的alpha通道
xxxxxxFF
有关。我在将
viridis
作为mapview包的默认调色板时也遇到了同样的问题。我写了一个小函数来解决这个问题。函数未导入命名空间,因此只能通过
mapview:::col2Hex
访问它。其定义如下:

function(col, alpha = FALSE) {

  mat <- grDevices::col2rgb(col, alpha = TRUE)
  if (alpha) {
    hx <- grDevices::rgb(mat[1, ]/255, mat[2, ]/255,
                         mat[3, ]/255, mat[4, ]/255)
  } else {
    hx <- grDevices::rgb(mat[1, ]/255, mat[2, ]/255, mat[3, ]/255)
  }
  return(hx)

}
尝试将alpha设置为
TRUE
,结果是没有颜色:

leaflet() %>% addTiles() %>% addLegend(
    position = 'bottomright',
    colors = mapview:::col2Hex(viridis(8), alpha = TRUE), 
    labels = mapview:::col2Hex(viridis(8), alpha = TRUE), opacity = 1)

传单的开发版本现在支持绿色调色板

leaflet() %>% addTiles() %>% addLegend(
    position = 'bottomright',
    colors = mapview:::col2Hex(viridis(8), alpha = TRUE), 
    labels = mapview:::col2Hex(viridis(8), alpha = TRUE), opacity = 1)