R 闪亮应用程序中的Unicode文本
我正在尝试制作包含表情符号的闪亮打印文本输出。不幸的是,它似乎没有打印表情符号,而是打印不同符号的Unicode数字,如下所示: 下面是一个简单的Shinny不处理表情符号的示例。它从R 闪亮应用程序中的Unicode文本,r,unicode,shiny,R,Unicode,Shiny,我正在尝试制作包含表情符号的闪亮打印文本输出。不幸的是,它似乎没有打印表情符号,而是打印不同符号的Unicode数字,如下所示: 下面是一个简单的Shinny不处理表情符号的示例。它从emoji.json文件中加载三个表情符号: {"emoji":["I think this depends on the encoding of your emoji.json file. When I copied your example file into TextEdit (I'm on a Mac),
emoji.json
文件中加载三个表情符号:
{"emoji":["I think this depends on the encoding of your emoji.json
file. When I copied your example file into TextEdit (I'm on a Mac), converted it to plain text, and saved it as a .json
with UTF-8
encoding, the emojis displayed correctly both in TextEdit and in the shiny app you posted.
I though the problem might be due to encoding, so I replaced the emojis with their hex equivalents and saved the file with Western (Windows Latin 1)
encoding so they appeared as plain text of hex numbers.
Getting them to display properly in Shiny simply required combining as.integer
to convert from Hex and intToUtf8
to render them as UTF8
characters.
JSON file with Hex representations of the emoji in Western (Windows Latin 1)
encoding:
{"emoji":["0x0001F605","0x0001F612","0x0001F62B"]}
{“emoji”:[“我认为这取决于你的emoji.json
文件的编码。当我将你的示例文件复制到TextEdit(我在Mac上),将其转换为纯文本,并使用UTF-8
编码将其保存为.json
,表情在TextEdit和你发布的闪亮应用程序中都能正确显示
我认为问题可能是由于编码,所以我用十六进制等价物替换了emojis,并用Western(Windows拉丁语1)
编码保存了文件,因此它们显示为十六进制数字的纯文本
要使它们正确地显示在文本中,只需将as.integer
与intToUtf8
组合,即可将它们转换为UTF8
字符
JSON文件,带有表情符号的十六进制表示形式,采用Western(Windows拉丁语1)
编码:
{“表情符号”:[“0x0001F605”、“0x0001F612”、“0x0001F62B”]
闪亮应用程序:
library(jsonlite)
图书馆(闪亮)
图书馆(tidyverse)
ui%
Sappy(函数(x){
intToUtf8(作为整数(x))
})
})
}
shinyApp(用户界面=用户界面,服务器=服务器)
表情符号将正确显示: