微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。