html - Timevis - 使用自定义 css 更改字体大小

标签 html css r shiny

我想生成一个 timevis 图,其中字体大小根据变量的重要性而变化。

使用源数据框中的“样式”选项,我可以更改字体颜色。但是,当我使用相同的方法尝试更改字体大小时,R 无法正确呈现变量。

这是我的数据示例:

data <-    structure(list(groups = c("Deadline.1", "Deadline.1", "Deadline.1", 
"Deadline.1", "Deadline.1"), content = c("Geography Tutorials: Critical 
Thinking & Techniques",  "Principles of Geographical Inquiry I", "Geography 
in Action", 
"Physical Geography: Earth Surface Processes & Landforms", "Biogeography & 
Ecology"
), start = structure(c(17459, 17505, 17631, 17911, 18048), class = "Date"), 
end = structure(c(17459, 17505, 17631, 17911, 18048), class = "Date"), 
type = c("point", "point", "point", "point", "point"), id = c(1L, 
2L, 7L, 9L, 10L), Assessment = c("1500 word essay ", "Group survey", 
"20% attendance (5% per block)", "2 hr exam ", "2 hr exam "
), Percentage = c(15, 15, 20, 100, 100), style = c("'font-size:15px;'", 
"'font-size:15px;'", "'font-size:20px;'", "'font-size:100px;'", 
"'font-size:100px;'")), row.names = c(NA, 5L), class = "data.frame")

这是我的代码的相关部分。显然在最终版本中,我会在“百分比”和字体大小之间做一个更微妙的链接功能。但无论字体大小如何,这都不起作用。

library(shiny)
library(timevis)
library(tidyr)
library(plyr)
library(dplyr)


data$style            <- paste0("'font-size:", data$Percentage, "px;'")


### example time vis rendering (doesn't work)

timevis(data = data[2:3, ])  ### random variable choice


### but this works

data$style            <- 'color: red'
timevis(data = data[2:3, ])

非常欢迎任何建议。我主要是一名建模师而不是应用程序开发人员,如果这是由于一个微不足道的 HTML 错误造成的,我深表歉意。

最佳答案

只需删除 ' 即可:

data$style <- paste0("font-size:", data$Percentage, "px;")
timevis(data = data[2:3, ])

enter image description here

关于html - Timevis - 使用自定义 css 更改字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55327211/

相关文章:

html - HTML div 上的不同 CSS 行为

javascript - Hello World phonegap 应用程序崩溃

php - 为什么 css 在 codeigniter 上不起作用?

r - 自然排序以按列名称对数据框的列进行排序

r - 我怎样才能改进这个R函数

html - 浏览器中的 Unicode 渲染问题

javascript - 用字母数字字符标记轴

HTML 电子邮件在 Outlook 2007 中无法正确显示

当 font-family 回退时,CSS 字体大小会发生变化

r - 依赖于其他参数的匹配参数的最佳实践