tags$style 应用于 R shiny 中的所有 Leaflet Maps

tags$style applied to all Leaflet Maps in R shiny

我可以在 R app regarding 中更改光标,但似乎无法弄清楚如何仅针对特定地图执行此操作。好像最后的tags$style 应用到之前的所有地图上了?我添加了一个只有两个地图的代表,但同样的逻辑可以应用于更多地图。任何帮助将不胜感激,因为它让我烦恼!谢谢

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)

不要在 css 中使用 class 选择器 .leaflet-container,而是使用 ID 选择器 #swe_maps#swe_maps2.

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)