The following error is shown in Rpresentation (From RStudio)
<!-htmlpreserve-> when rendering a tauchart on one of the presentation slides.
Whereas with ioslides there is no error and the graph is plotted nicely and keeps all its interactivity.
Do I need to add an additional parameter in the chunk options? Or do I need to specifically assign print to the object?
Code:
```{r,warning=FALSE,error=FALSE,message=FALSE,echo=FALSE}
tauchart(df) %>%
tau_stacked_bar(x="x",y="y",color="color") %>%
tau_legend() %>% tau_tooltip()
```
Related
Can't find generic `sew` in package knitr to register S3 method.
i This message is only shown to developers using devtools.
i Do you need to update knitr to the latest version?
I keep receiving the above error when I try to knit my rmarkdown file to html.
All I am doing is cleaning up my dataset with dplyr (select, mutate,etc.)
And generating cross tabs with the expss package
I am not using devtools. In fact, I didn't even have the package installed when the error appeared.
My code was knitting to html just fine. All I did was copy my code and change one variable (Race to Ethnicity), and then knit to HTML stopped working. It was working minutes before.
To fix this, I have tried:
knit to PDF (same error)
updating knitr and rmarkdown and expss
installing devtools and running library(devtools)
Closing out R and restarting my session
Clearing out my global environment and re-running everything
deleting the new code and running the original code that was working minutes before
None of these things worked! Any idea what could have happened with R markdown?
All I do is read in my excel sheet into "FullData"
And then I run this code
```{r, include = FALSE}
Racedata <- FullData %>%
select(Coder, Link, Chamber, SenateCommittee, SenateSubcommittee, HouseCommittee, HouseSubcommittee, Name, BillType, BillNumber, Race1, Race2) %>%
#Fix issues with Race columns
mutate(Race2 = na_if(Race2, "Other")) %>%
mutate(Race2 = na_if(Race2, "White"))
#Combine 2 Race columns into 1
Racedata$Race2 <- gsub("Unknown", "Audio Only", Racedata$Race2)
Newrace <- data.frame(Race = with(Racedata, replace(Race2, is.na(Race2), Race1[is.na(Race2)])))
Racedata$Race <- Newrace$Race
Racedata <- Racedata %>%
select(-c(Race1, Race2))
```
The code works just fine when I run it, but the error occurs when I try to knit to html.
This is the table that I want to produce with Knit to HTML:
```{r RACE CHARTS, echo = FALSE}
cross_cpct(Racedata, Race, list(total(), Chamber, HouseCommittee, SenateCommittee))
```
I figured it out! Stupid mistake
Two of my code blocks had the same name (facepalm)
UNRAVEL_study %>%
group_by(sleep_dep) %>%
summarise(mean=mean(unravel), SD=sd(unravel), min=min(unravel), max=max(unravel), IQR=IQR(unravel))
how do I get a presentable table that gives me the same info as this code chunk? im trig to do a presentation for class and we can't show any code
Ok, this is how I fixed it:
UNRAVEL_study %>%
group_by(sleep_dep) %>%
summarise(mean=mean(unravel), SD=sd(unravel), min=min(unravel), max=max(unravel), IQR=IQR(unravel))%>%
kable(., caption = "sleep deprivation descriptive statistics")
I used the Kable function which makes it into a really tidy table. Then up top I added the directions echo=FALSE to not include the code, and message=FALSE to not include the R console
I am trying to create a table in R. I used mtcars as ax example dataset. I keep getting the error below. I am truly at a loss for how exactly to fix this and where to move certain files or programs to (ghostscript, magick, phantomjs..). Is there an easy fix? I am not using markdown.
kable(rawCSV, "latex", booktabs = T) %>%
kable_styling(latex_options = c("solid", "scale_down")) %>%
as_image()
save_kable(file="table.pdf")
Error in save_kable_latex(x, file, latex_header_includes, keep_tex, density) :
We hit an error when trying to use magick to read the generated PDF file. You may check your magick installation and try to use magick::image_read to read the PDF file manually. It's also possible that you didn't have ghostscript installed.
i'm trying to make my knitr tables (through KableExtra package) more appealing by adding some of the functions of the formattable package (i.e. colortile, ...).
But when running the code, the table gets visualized, but the table does not render the elements of the formattable. However I can see the HTML code in the table where the formattable functions would have to take place (6th column in the printscreen below):
This is my code to render the table:
input_file %>%
mutate(
month_perc = color_bar("lightgreen")(month_perc)) %>%
kable(format = 'html')%>%
kable_styling(bootstrap_options = c("hover","striped"))
Probably this is an easy fix, but does anyone have an idea why it doesn't render?
Thanks in advance!
Kind regards,
Simon
You need escape=F in your kable function.
I am using blogdown to to create a blogpost that has a series of tables. Creating a single table using the kable function works fine. If you do
blogdown::new_site()
blogdown::new_post("test", ext = ".rmd")
A new rmd file will be created within the content/post directory of the project. If you open that file and create a single table by doing
```{r test1}
library(knitr)
library(magrittr)
library(shiny)
data.frame(a= c(1,2,3)) %>% kable(caption = 'test',format = 'html')
```
A correctly formatted table will be generated. The caption will read "
Table 1: test" If you look at the code of the generated site, the caption will look like this.
<caption>
<span id="tab:test1">Table 1: </span>test
</caption>
Ideally I don't have any desire to label the table as Table 1 in the first place but that is another question. If formatting of captions by kable can be disabled entirely, I'd also be happy.
However if I use lapply to generate 2 tables instead
```{r test2}
lapply(1:2,function(x){
data.frame(a= c(1,2,3)) %>% kable(caption = 'test2',format = 'html') %>% HTML()
}) -> tables
tables[[1]]
tables[[2]]
```
The captions will have the prefix \#tab:test2. If you look at the caption of these tables, you'll see
<caption>(\#tab:test2)test2</caption>
The question is, why kable behaves differently when its called from a lapply compared to its behaviour outside? Note that both of these behaviours are different that its behaviour when simply knitting the file as an html_document.
I did some digging into the kable's code and found that the caption link is created by the knitr:::create_label function. Looking into this function, I saw the part that is responsible for the wrong behaviour seen with the multiple tables.
if (isTRUE(opts_knit$get("bookdown.internal.label"))) {
lab1 = "(\\#"
lab2 = ")"
}
I could not find the code, responsible for the "correct" behaviour with the single table but it seems like knitr internal options are responsible.
Ultimately the behaviour that I want is simply
<caption>test</caption>
which is the behaviour when simply knitting an html document. But I am yet to find a way to set the relevant knitr options and why are they different within the same document.
Edit: Further examination suggests that the issue isn't lapply specific. It can be replicated using a for loop or even { by itself. A complete post with all the problematic examples can be acquired from this issue on knitr's github page. This github repo includes the basic blogdown site that replicates the issue
Turns out the responsible party is not the lapply call but the HTML call at the end. It seems like the regular process by knitr in blogdown and bookdown is to have a temporary marker for the table references in the form of (\#tab:label) and replace it with the appropriate syntax later in the processing.
I was using the HTML call to be able to use the tags object in shiny/htmltools to bind the tables together. This approach seems to make the process of replacing the temporary marker impossible for reasons outside my understanding. For my own purposes I was able to remove the temporary marker all together to get rid of both malformed captions and the working-as-intended table numbers by doing
remove_table_numbers = function(table){
old_attributes = attributes(table)
table %<>% as.character() %>% gsub("\\(\\\\#tab:.*?\\)","",.)
attributes(table) = old_attributes
return(table)
}
data.frame(a= c(1,2,3)) %>% kable(caption = 'test',format = 'html') %>% remove_table_numbers
This question still would benefit from a proper explanation of the reference link placement process and if its possible to apply it to tables in HTML calls as well. But for know this solves my issue. I'll gladly switch the accepted answer if a more complete explanation appears