首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >标签$style应用于R闪亮中的所有叶地图

标签$style应用于R闪亮中的所有叶地图
EN

Stack Overflow用户
提问于 2020-11-04 03:40:55
回答 1查看 149关注 0票数 0

我可以更改R shiny应用程序中有关r-leaflet的光标,但似乎不知道如何仅针对特定地图执行此操作。似乎最后一个tags$style应用于所有以前的地图?我已经添加了一个只有两个map的reprex,但是相同的逻辑可以应用于更多的map。任何帮助都是非常感谢的,因为它让我抓狂!谢谢。

代码语言:javascript
复制
library(shinydashboard)
library(leaflet)
library(tidyverse)

header = dashboardHeader(title = "Hydroclimatic Data")


# * sidebar ----
sidebar = dashboardSidebar(
  sidebarMenu(
    menuItem(
      "Map",
      tabName = "map",
      menuSubItem("Map", tabName = "map", icon = icon("chart-line"))
    ),
    menuItem(
      "Map2",
      tabName = "map2",
      menuSubItem("Map2", tabName = "map2", icon = icon("chart-line"))
    )))



body = dashboardBody(
  tabItems(
    tabItem(
      tabName = "map",
      tags$style(type = 'text/css', '
      .leaflet-container {
  cursor: crosshair !important;}'),
      fluidRow(
        tabBox(width = 12, id = "tab",
               tabPanel("Map", style = "height:92vh;",leafletOutput("swe_maps"))))
      ),
    
    
    # * * -- Snotel - Raw ----
    tabItem(
      tabName = "map2",
      tags$style(type = 'text/css', '
      .leaflet-container {
  cursor: help !important;}'),
      fluidRow(
        tabBox(width = 12, id = "tabchart",
               tabPanel("Map", style = "height:92vh;",leafletOutput("swe_maps2")))))))
  
  # UI ----------------------------------------------------------------------
  
  ui <- dashboardPage(header = header, sidebar = sidebar, body = body)
  
  # Server ------------------------------------------------------------------
  
  
  server <- function(input, output, session) {
    
    output$swe_maps <- renderLeaflet({leaflet("map1") %>% addTiles()})
    
    
    output$swe_maps2 <- renderLeaflet({leaflet("map2") %>% addTiles()})
    
    
  }



##### RUN APPLICATION #####
shinyApp(ui = ui, server = server)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-06 23:10:02

使用Id选择器#swe_maps#swe_maps2,而不是在css中使用类选择器.leaflet-container

代码语言:javascript
复制
library(shinydashboard)
library(leaflet)
library(tidyverse)
library(shiny)

header = dashboardHeader(title = "Hydroclimatic Data")


# * sidebar ----
sidebar = dashboardSidebar(
  sidebarMenu(
    menuItem(
      "Map",
      tabName = "map",
      menuSubItem("Map", tabName = "map", icon = icon("chart-line"))
    ),
    menuItem(
      "Map2",
      tabName = "map2",
      menuSubItem("Map2", tabName = "map2", icon = icon("chart-line"))
    )))



body = dashboardBody(
  tabItems(
    tabItem(
      tabName = "map",
      tags$style(type = 'text/css', '
      #swe_maps {
  cursor: crosshair !important;}'),
      fluidRow(
        tabBox(width = 12, id = "tab",
               tabPanel("Map", style = "height:92vh;",leafletOutput("swe_maps"))))
    ),
    
    
    # * * -- Snotel - Raw ----
    tabItem(
      tabName = "map2",
      tags$style(type = 'text/css', '
      #swe_maps2 {
  cursor: help !important;}'),
      fluidRow(
        tabBox(width = 12, id = "tabchart",
               tabPanel("Map", style = "height:92vh;",leafletOutput("swe_maps2")))))))

# UI ----------------------------------------------------------------------

ui <- dashboardPage(header = header, sidebar = sidebar, body = body)

# Server ------------------------------------------------------------------


server <- function(input, output, session) {
  
  output$swe_maps <- renderLeaflet({leaflet("map1") %>% addTiles()})
  
  
  output$swe_maps2 <- renderLeaflet({leaflet("map2") %>% addTiles()})
  
  
}



##### RUN APPLICATION #####
shinyApp(ui = ui, server = server)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64669524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档