Coder Social home page Coder Social logo

Encoding issues about highcharter HOT 10 CLOSED

jbkunst avatar jbkunst commented on June 22, 2024
Encoding issues

from highcharter.

Comments (10)

shrektan avatar shrektan commented on June 22, 2024 1

@Funnng covert the UTF8 character to native might help

from highcharter.

shrektan avatar shrektan commented on June 22, 2024

I guess it's something related to the handling of R object to JSON.

Note, if I remove the last Chinese character , the code works fine, i.e.:

library(magrittr)
r <- data.frame(a = 1:3, b = c("a", "b", "c"))
highcharter::highchart() %>%
  highcharter::hc_chart(type = "column") %>%
  highcharter::hc_xAxis(categories = r$b) %>%
  highcharter::hc_add_series(data = r$a, name = "权益")

from highcharter.

shrektan avatar shrektan commented on June 22, 2024

I guess it's not an error related to your package, because I find that the DT can't work as well.

DT::datatable(data.frame(name = "权益类"))

So, feel free to close this issue if you end up with the same conclusion. Thanks!

from highcharter.

shrektan avatar shrektan commented on June 22, 2024

@jbkunst Sorry, after I reboot my PC, the issue is gone... Sometimes, the best solution in Windows is rebooting... So, I'll close this issue.

from highcharter.

jbkunst avatar jbkunst commented on June 22, 2024

😆 Sometimes? Always!

Regards

from highcharter.

glfeng318 avatar glfeng318 commented on June 22, 2024

i got the same problem on centos.

from highcharter.

jbkunst avatar jbkunst commented on June 22, 2024

Hi @Funnng,

If you have the same message/error:

Error in gsub("</", "\\u003c/", payload, fixed = TRUE) :

That line belogs to the htmlwidgets package (see line here)

So I'm not sure how I can help you. Have you tried removing special characters?

from highcharter.

glfeng318 avatar glfeng318 commented on June 22, 2024

i tried the code below and it show nothing, and i check the console log in chrome and found this error.

highchart() %>% hc_add_series_treemap(treemap(data.frame(city=c('广州','广州','佛山','佛山'), zone=c('天河','海珠','顺达','禅城'), pay = c(563,235)), index = c('city','zone'), vSize='pay', vColor='pay', type='comp', palette = rev(viridis(9)), draw = F))

hc2
hc

from highcharter.

glfeng318 avatar glfeng318 commented on June 22, 2024

@jbkunst @shrektan i think it is not the same issue, the error i met is not like Error in gsub("</", "\\u003c/", payload, fixed = TRUE) :

> devtools::session_info()
Session info -------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.3 (2015-12-10)
 system   x86_64, linux-gnu           
 ui       RStudio (0.99.892)          
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       <NA>                        
 date     2016-05-23                

from highcharter.

jbkunst avatar jbkunst commented on June 22, 2024

Hi @Funnng

The issue is because internally the hc_add_series_treemap function is using a helper function str_to_id which try to remove spectial character to put the name of the value as id in the data series (check str_to_id("广州")).

By now, you can use a modify hc_add_series_treemap2 (see code below) until I check if there no problem if I remove some replacement in the str_to_id function.

library(dplyr)
library(purrr)

hc_add_series_treemap2 <- function(hc, tm, ...) {

  df <- tm$tm %>% 
    tbl_df() %>% 
    select_("-x0", "-y0", "-w", "-h", "-stdErr", "-vColorValue") %>% 
    rename_("value" = "vSize", "valuecolor" = "vColor") %>% 
    purrr::map_if(is.factor, as.character) %>% 
    data.frame(stringsAsFactors = FALSE) %>% 
    tbl_df()

  ndepth <- which(names(df) == "value") - 1

  ds <- map_df(seq(ndepth), function(lvl){ # lvl <- sample(seq(ndepth), size = 1)

    df2 <- df %>% 
      filter_(sprintf("level == %s", lvl)) %>% 
      rename_("name" = names(df)[lvl]) %>% 
      mutate_("id" = "name")

    if (lvl > 1) {
      df2 <- df2 %>% 
        mutate_("parent" = names(df)[lvl - 1],
                "parent" = "parent")
    } else {
      df2 <- df2 %>% 
        mutate_("parent" = NA)
    }

    df2 

  })

  ds <- list.parse3(ds)

  ds <- map(ds, function(x){
    if (is.na(x$parent))
      x$parent <- NULL
    x
  })

  hc %>% hc_add_series(data = ds, type = "treemap", ...)

}

from highcharter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.