小编Viv*_*viG的帖子

在“asis”R Markdown 块中初始化 JS 渲染器的推荐方法

'asis' 块对于在 Markdown 文档中输出对象列表非常有用,请参阅以下示例:HighcharterDTLeaflet,...

但是,在上面的示例中,如果渲染器在前一个块中没有被调用一次,则对象列表将不会打印,以便它被初始化:这是一个棘手的解决方法,我通过试验找到了更多解决方案/错误比通过在文档中查找它更容易。

这是一个可重现的问题,也发布在https://github.com/rstudio/rmarkdown/issues/1877上:

---
title: "Test"
output:
  html_document
---



```{r,echo=F}
library(DT)
library(rmarkdown)
library(purrr)
library(knitr)

df_list <- list("cars" = mtcars, "flowers" = iris)

knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
```

```{r}
# If this first initialization isn't run, tabs won't print
DT::datatable(data.frame())
```

# Test tabs {.tabset}

```{r, results='asis' }
imap(df_list, ~{
  cat('## Subtab ',.y,'\n')
  cat('\n')
  DT::datatable(.x) %>%
    htmltools::tagList() %>% as.character() %>% cat() })

```
 

  
Run Code Online (Sandbox Code Playgroud)

r knitr r-markdown

7
推荐指数
2
解决办法
1021
查看次数

使用 cairo 在轴标题中保存带有表达式和 unicode 的 ggplot

我想保存以下情节:

library(ggplot2)

myplot <- ggplot(iris) +
  geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
  ylab(expression(~delta^13*C~"[\211]"))

ggsave(myplot, 
       filename = "myplot.png", 
       type = "cairo")
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  Metric information not available for this family/device
Run Code Online (Sandbox Code Playgroud)

问题一定是表达式和​​ unicode 的组合,因为这两者可以工作:

myplot <- ggplot(iris) +
  geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
  ylab("[\211]")

myplot <- ggplot(iris) +
  geom_point(aes(x = Sepal.Width, y = Sepal.Length)) +
  ylab(expression(~delta^13*C))
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?

编辑:我想打印“千分之一”符号。显然它的unicode是U2030,我错误地认为“\211”是一个unicode,但一定是别的东西。

编辑2:与此同时,我发现这个问题也有类似的问题。在那里,一个建议是用 保存情节encoding = "MacRoman",不幸的是这对我不起作用:

Error in png_dev(..., res = …
Run Code Online (Sandbox Code Playgroud)

r cairo ggplot2

6
推荐指数
1
解决办法
1063
查看次数

如何在 R Shiny 应用程序中对齐 downloadButton 和 ActionButton?

我有一个 Shiny 应用程序,侧边栏上有两个按钮,但我无法对齐它们。我尝试了此处给出的解决方案(Shiny R 对齐按钮),但它对我不起作用。

这是它们的样子

这是一个可重现的代码:


library(shiny)
library(DBI)
library(shinydashboard)
library(DT)
library(shinyjs)


ui <- dashboardPage(
#Header 
  dashboardHeader(title = "Labware dashboard"),
#Sidebar with download button  
  dashboardSidebar(
    width = 130,
    downloadButton('downloadData',
                   'Download',
                   style = "color: #fff; background-color: #27ae60; border-color: #fff"),
#Create a button in the sidebar to stop app
    useShinyjs(),
    extendShinyjs(text = jscode, functions = ("closeWindow")),
    actionButton("close", "Close window", 
                icon("close"),
               style = "color: #fff; background-color: red; border-color: #fff")
  ),
  
  dashboardBody()
  
  )


server <- function(input, output, session) {
  

  #close the …
Run Code Online (Sandbox Code Playgroud)

r button shiny

2
推荐指数
1
解决办法
473
查看次数

标签 统计

r ×3

button ×1

cairo ×1

ggplot2 ×1

knitr ×1

r-markdown ×1

shiny ×1