R中的reactablefmtr包在RStudio查看器中生成表,但不是在新窗口中输出html [关闭]
Posted
技术标签:
【中文标题】R中的reactablefmtr包在RStudio查看器中生成表,但不是在新窗口中输出html [关闭]【英文标题】:reactablefmtr package in R produce table in RStudio viewer but not html output in new window [closed] 【发布时间】:2022-01-21 04:38:49 【问题描述】:我正在尝试使用 R 中的“reactablefmtr”包生成一个包含多个页面的大表。它在 RStudio 查看器中生成表格,但不在新窗口中生成 html 输出。 Microsoft Edge 是我在 RStudio 中的默认 Web 浏览器。这与我的代码有关,因为我使用“reactablefmtr”和 Microsoft Edge 成功生成了其他几个表。
下面是我的代码:
data <- as_tibble(data, rownames = "date") %>% select (-actual2)
temppal <- c("#36a1d6", "#76b8de", "#a0bfd9", "#ffffff", "#d88359", "#d65440", "#c62c34")
reactable(
df,
defaultColDef = colDef(
style = color_scales(data, span = TRUE, colors = temppal),
minWidth = 50
)
)
【问题讨论】:
也许,在 RMarkdown 中制作? 您没有提供足够的关于您的设置和加载的包的信息。另外,我没有看到任何reactablefmtr
代码。需要调试细节。
【参考方案1】:
我解决了这个问题,它与我的数据格式有关。
这里是可重现的代码和输出:
library(tidyverse)
library(reactablefmtr)
df<- data.frame(c(2875,2755,2440,2220,1378,1352,2616,1709,1475,2315,2223,4357,3037,1725,2332,2358,3135,3232,3497,2876,2971,3530,4268,4692,3589,3496,4233,4336,5810,6943,8921,7491),
c(2714,2393,2144,2100,1378,1533,2918,1609,1697,2407,2168,2880,2336,2574,3110,2383,2769,3282,3307,2959,2988,3633,3671,4138,3294,3241,3915,3951,4921,5874,6626,6571),
c(2790,2478,2170,2048,1325,1513,2944,1637,1670,2346,2122,2907,2369,2540,2678,2329,2717,3121,3281,2932,2919,2936,3578,4056,2735,2654,4185,4245,5503,6550,7371,5026),
c(2809,2493,2167,2031,1310,1511,2954,1648,1670,2335,2112,2915,2395,2562,2795,2321,2709,3120,3284,2943,2921,3525,3573,4059,3219,3160,3842,3835,4764,5664,6394,6349),
c(2685,2623,2443,2104,1129,1212,2889,1370,1474,2378,2289,2937,2113,2508,3186,2417,2738,3122,3322,2979,2937,3479,3674,4047,3227,3277,4004,3916,4750,5556,6473,6521),
c(2788,2731,2490,2161,1188,1298,3048,1352,1402,2348,2328,3066,1936,2223,3199,2487,2853,3282,3282,3114,3041,3668,3950,4317,2985,2968,4093,4077,5120,6045,6915,5778),
c(2788,2624,2373,2087,1185,1303,2914,1423,1476,2324,2229,2983,2129,2369,2987,2402,2774,3178,3316,2948,2938,3453,3691,4092,3076,3073,3959,3951,4862,5728,6529,6034),
c(2899,2735,2485,2199,1297,1414,3026,1535,1588,2435,2341,3095,2241,2480,3098,2513,2886,3289,3427,3060,3050,3564,3803,4204,3188,3184,4071,4063,4974,5839,6641,6146),
c(2616,2575,2601,2138,1291,1288,2525,1352,1378,2220,1907,2875,1709,1475,2315,2224,2616,2868,3037,2332,2358,3135,3232,3497,2479,2382,2876,2971,3530,4268,4692,3589),
c(2773,2678,2495,2125,1055,1064,2927,1215,1343,2338,2321,2997,1972,2259,3084,2468,2808,3157,3325,2968,2962,3461,3685,4039,3053,3150,3986,3918,4689,5490,6334,6214),
c(2917,2796,2457,2036,1076,1243,3078,1371,1338,2223,2265,3104,2089,2333,2993,2406,2815,3235,3413,2939,2957,3514,3787,4169,3165,3155,3998,4016,4871,5657,6441,6259),
c(2769,2683,2518,2100,1141,1198,2847,1313,1353,2260,2164,2992,1923,2022,2797,2366,2746,3087,3258,2746,2759,3370,3568,3902,2899,2896,3620,3635,4363,5138,5822,5354),
c(2845,2737,2476,2081,1066,1154,3003,1293,1341,2281,2293,3051,2031,2296,3039,2437,2812,3196,3369,2954,2960,3488,3736,4104,3109,3153,3992,3967,4780,5574,6388,6237)
)
#Naming the Data Frame
names(df) <- c("actual", "hw1","ets2","hw3","sarima","hybrid","consensus1","consensus2",
"naïve","arima","ets", "mixed1", "mixed2")
df
temppal <- c("#36a1d6", "#76b8de", "#a0bfd9", "#ffffff", "#d88359", "#d65440", "#c62c34")
reactable(
df,
pagination = FALSE,
showSortIcon = TRUE,
defaultColDef = colDef(
header = function(value) gsub(".", " ", value, fixed = TRUE),
cell = function(value) format(value, nsmall = 1),
align = "center",
headerStyle = list(background = "#f7f7f8"),
style = color_scales(data, span = TRUE, colors = temppal),
minWidth = 100
)
)
%>%
add_title("Covid19 Forecasts for Canada as of Dec-14") %>%
add_source("Data sourced from Our World in Data")
https://rpubs.com/stepminer/849175
【讨论】:
感谢您发布此问题的解决方案。您可以在 48 小时后将您的答案标记为已接受的答案,此时可以标记。它可以在未来帮助其他社区成员解决类似的问题。感谢您的理解。以上是关于R中的reactablefmtr包在RStudio查看器中生成表,但不是在新窗口中输出html [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
R Markdown 无法获取 RStudio 版本 - knit 中的错误消息
r 将MS Access数据库连接到Windows中的R(RStudio)