tags $ style应用于R Shiny中的所有传单地图

问题描述

我可以在有关的R 应用中更改光标,但似乎无法弄清楚如何仅对特定地图进行操作。好像最后一个tags$style是否应用于所有先前的地图?我只添加了两个地图的reprex,但是相同的逻辑可以应用于更多地图。任何帮助将不胜感激,因为它使我讨厌胡扯!谢谢。

library(shinydashboard)
library(leaflet)
library(tidyverse)

header = dashboardHeader(title = "Hydroclimatic Data")


# * sidebar ----
sidebar = dashboardSidebar(
  sidebarMenu(
    menuItem(
      "Map",tabName = "map",menuSubItem("Map",icon = icon("chart-line"))
    ),menuItem(
      "Map2",tabName = "map2",menuSubItem("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",'
      .leaflet-container {
  cursor: help !important;}'),id = "tabchart",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)

解决方法

使用Id选择器.leaflet-container#swe_maps代替在CSS中使用类选择器#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",icon = icon("chart-line"))
    ),menuItem(
      "Map2",tabName = "map2",menuSubItem("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",'
      #swe_maps2 {
  cursor: help !important;}'),id = "tabchart",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)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...