RShiny Error in showModal(ModalDialog(h3(...):“Warning:Error in writeImpl:Text to be written must be length-one character vector”

sgtfey8w  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(105)

我创建了一个名为mingiPolyvector的包。它识别ggplot包形成的Map可视化中的多边形对象。我已经使它与sf包中的数据兼容。当创建一个带有弹出消息的 Jmeter 板时,我得到了这个错误,“警告:writeImpl中的错误:要写入的文本必须是长度为一个字符向量”。这是代码

library(tidyverse)
library(sf)
library(reactable)
library(rsconnect)
library(shiny)
library(shinythemes)
library(mingiPolygons)
library(shinyjs)

nameshp <- system.file("shape/nc.shp", package="sf")
tableau <- read.csv('childcare modified.csv')

# GET DATA FROM NORTH CAROLINA COUNTY
nc_tab <- tableau %>%
  filter(state_name == "North Carolina")

dream <- st_read(nameshp, quiet=TRUE)
dream$vble <- dream$SID74
dream$vble2 <- dream$SID79

# merge datasets
d <- merge(x=dream, y=nc_tab, by.x = "FIPSNO", by.y="county_fips_code", all=TRUE)

server <- function(input, output, session){
  output$plot <- renderPlot({
    ggplot(d)+
      geom_sf(aes(fill=vble))+
      scale_fill_distiller(palette="YlGnBu", direction=1)
  })
  
  d_reactive <- reactiveVal(NULL)
  
  tryCatch({
    observeEvent(input$plot_click, {
      d_reactive(d)
      kristy <- mingiPolygons:::preWork(d_reactive(), "NAME")
      county_choice <- mingiPolygons(kristy, input$plot_click, "NAME", 50, 4)
      sel_county_data <- d_reactive()[d_reactive()$NAME == as.character(county_choice),]
      
      if(!is.null(sel_county_data)){
        showModal(modalDialog(
          h3(as.character(sel_county_data[1, "NAME"]))
        ))
      } else if (is.null(sel_county_data)){
        showModal(ModalDialog(
          h2("The data is the problem. There is no information")
        ))
      }
    })
  })
  
  
}


ui <- fluidPage(
  theme = shinytheme("cerulean"),
  tags$div(class="jumbotron text-center",
           style="margin-bottom:30px:margin-top:0px;height:10px;background-color: dodgerblue;color:ivory;font-size:30px",
           "New Sample"),
  fluidRow(column(12, plotOutput("plot", click='plot_click')))

)
shinyApp(ui=ui, server=server)

字符串
一些要求:
1.安装mingiPolyclonal软件包:devtools::install_github("mmburu8/mingiPolygons")更多信息:https://mmburu8.github.io/mingiPolygons/

  1. Download“childhood modified.csv”:https://drive.google.com/drive/folders/1gl2CYv5mBJdV0Px45rokZzQwV66aVleU?usp=sharing
    我的主要假设是变量“d”中的数据,用于评估多边形对象,并且包含未处理的信息。任何建议都将有所帮助。
gkl3eglg

gkl3eglg1#

当对一个sf对象进行子集设置时,它有一个geometry列,即使没有显式选择,它也会被返回。因此,在你的h3调用中,你不是传递一个字符串,而是一个sf对象,这让h3发出警告。
补救措施很简单:显式删除geometry列:

### [...]
h3(sel_county_data[1, "NAME", drop = TRUE])
## or
## h3(st_drop_geometry(sel_county_data)[1, "NAME"]))

字符串

相关问题