Is there any way to reduce the right and left margins when shiny-server sees an .Rmd file instead of ui.R and server.R? As you can see below, nearly half of the window is right and left margins. Is there a way to modify an internal css script to make the change or is there a more simple solution by adding an geometry option in the markdown header?
Here is the sample code generated when I create a new Shiny Rmarkdown file in Rstudio:
---
title: "Untitled"
author: "Me"
date: "10/13/2015"
output: html_document
runtime: shiny
---
This R Markdown document is made interactive using Shiny. Unlike the more traditional workflow of creating static reports, you can now create documents that allow your readers to change the assumptions underlying your analysis and see the results immediately.
To learn more, see [Interative Documents](http://rmarkdown.rstudio.com/authoring_shiny.html).
## Inputs and Outputs
You can embed Shiny inputs and outputs in your document. Outputs are automatically updated whenever inputs change. This demonstrates how a standard R plot can be made interactive by wrapping it in the Shiny `renderPlot` function. The `selectInput` and `sliderInput` functions create the input widgets used to drive the plot.
```{r, echo=FALSE}
inputPanel(
selectInput("n_breaks", label = "Number of bins:",
choices = c(10, 20, 35, 50), selected = 20),
sliderInput("bw_adjust", label = "Bandwidth adjustment:",
min = 0.2, max = 2, value = 1, step = 0.2)
)
renderPlot({
hist(faithful$eruptions, probability = TRUE, breaks = as.numeric(input$n_breaks),
xlab = "Duration (minutes)", main = "Geyser eruption duration")
dens <- density(faithful$eruptions, adjust = input$bw_adjust)
lines(dens, col = "blue")
})
```
## Embedded Application
It's also possible to embed an entire Shiny application within an R Markdown document using the `shinyAppDir` function. This example embeds a Shiny application located in another directory:
```{r, echo=FALSE}
shinyAppDir(
system.file("examples/06_tabsets", package="shiny"),
options=list(
width="100%", height=550
)
)
```
Note the use of the `height` parameter to determine how much vertical space the embedded application should occupy.
You can also use the `shinyApp` function to define an application inline rather then in an external directory.
In all of R code chunks above the `echo = FALSE` attribute is used. This is to prevent the R code within the chunk from rendering in the document alongside the Shiny components.
After looking at the HTML produced by an Rmd file, it looks like the main content is under a div with class main-content and it has a max-width property. Looking at the rmarkdown source code, I believe that perhaps this happens here. Try adding a css rule like div.main-container { max-width: inherit; }
The above CSS change did not work for me, as I am having the same issue rendering HTML from Rmd in RStudio, but this did work. Added after YAML in Rmd:
<style>
.main-container {
max-width: 940px;
margin-left: 0;
margin-right: auto;
}
</style>
Related
I would like to insert a png "logo.png" inside my rMarkdown report. The current solution is working only when the png is in the root directory of the html report. However, when I send the report to someone, the missing png is an issue, since the person has only the html without the accompanied logo.
My idea is to read and to save the png beforehand and then to insert this r object in the html code chunk. However, I am having issues with this approach. Any help or other ideas are very much appreciated!
<script>
$(document).ready(function() {
$head = $('#header');
$head.prepend('<img src=\"logo.png\" style=\"float: right; width: 300px; padding-top: 20px; padding-left: 35px\"/>')
});
</script>
You can use an R chunk to import the png
```{r pressure, echo=FALSE, fig.cap="A caption", out.width = '100%'}
knitr::include_graphics("logo.png")
```
Example taken from this closed question
I would like to add a hyperlink function to a PNG I have added to my flexdashboard.
I've managed to add a hyperlink to a text as shown in the code below (in the first section), but I would like to add it to the PNG icon I have added in the second section of my code
---
title: "PNG Hyperlink"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
# Homepage
## Column {data-width=500}
### Introduction
<font size = "5">Please read user manual before exploring this dashboard. You can find user manual by clicking <a href="file:///C:/Users/Filip/Desktop/Dashboard%20guide.htm" target=_blank>here</a></font><br><br><br>
### Introduction 2
<font size = "5">Please read user manual before exploring this dashboard. You can find user manual by clicking the following icon</font><br><br><br>
```{r}
knitr::include_graphics("document-icon.png")
```
Additionally, it would be great if someone knows how to make this picture smaller and wrap text arround it.
Add an href attribute.
This should work
I have managed to solve this issue by working with the code following #samarmohan input.
Here is the code
### Introduction 2
<font size = "5">Please read user manual before exploring this dashboard. You can find user manual by clicking the following icon</font><br><br><br>
<a href="file:///C:/Users/Filip/Desktop/Dashboard%20guide.htm" target=_blank><center>
```{r dpi=10}
knitr::include_graphics("document-icon.png")
```
</center></a>
I have added href in order to add hyperlink to the icon and make the icon smaller using dpi = inside the {r} box
I have a dataframe with two columns, one is the name of FB pages, the other is the link of that page.
name.page link.page
"FBpage1" "http://facebook/FBpage1"
"FBpage2" "http://facebook/FBpage2"
"FBpage3" "http://facebook/FBpage3"
"FBpage4" "http://facebook/FBpage4"
and I want the output will be only the name.page with hyperlink, so I can click the page name and link to that FBpage.
name.page
"FBpage1"
"FBpage2"
"FBpage3"
"FBpage4"
I am using R2HTML but don't know how to do it,
any suggestions?
Thank you!
I don't know about using the R2html package, but basically what I gather is that you need a way to generate the markup for each link so that within the table there is a direct link to the page? For demonstrtion purposes im using htmltools and knitr to accomplish this.
PS please use dput so we can more easily reproduce your data in the future:
the part that produces the markup is in the pipe ...
read.table(
textConnection('name.page link.page
"FBpage1" "http://facebook/FBpage1"
"FBpage2" "http://facebook/FBpage2"
"FBpage3" "http://facebook/FBpage3"
"FBpage4" "http://facebook/FBpage4"')) %>% {
colnames(.) <- as.character(.[1,])
.[-1,] %>% mutate(
link_display =
sprintf('%s', link.page, name.page)
) %>%
knitr::kable(., format = "html", escape = FALSE) %>%
htmltools::HTML() %>%
htmltools::html_print()
}
So using sprintf I placed the link in the href attribute which is the html markup command for creating an external link and then used the name column as the display text which results in:
I'm trying to put a link on my "home" tabPanel to all others tabPanels of my app.
The idea is as follows:
ui = navbarPage("",
tabPanel("home",
fluidPage(
fluidRow(box("this 1st box should lead me to tab1a")),
fluidRow(box("this 2nd box should lead me to tab1b")),
fluidRow(box("this 2nd box should lead me to tab2")))
),
navbarMenu("tab1",
tabPanel("tab1a"),
tabPanel("tab1b")),
tabPanel("tab2")
)
shinyApp(ui, server=function(input, output) {})
I've seen the answer in Add link panel tabs in Shiny with various top level navigation bars, but I couldn't implement it on my code, since it deals with html (which i've never worked before, so I'm not familiar with the functions etc) and the code considers tabPanels within the same tab (not sure if that's why it didn't work here, if maybe it didn't work because the tabs I'm trying to link are on a navbarPage or something).
Can anyone help me or tell me where i could learn how to implement this on my example?
This answer is purely JavaScripted, but very minimal, I guess. Since Shiny creates tabs with random number Ids, and does not give access to the Ids it used, this has do be done client-sided. But there is no knowledge of JavaScript needed to implement this to other scenarios. The JavaScript part is just for Copy/Paste and the trigger command is easy to understand.
What did I do? I installed a function, that finds the Navbar link corresponding to the desired tab, and just clicks it. This utility can be added to any element with the "onclick" attribute. There are no special tags (e.g. no "a" tag) required.
The code below should make it easy to customize this solution to fit your needs.
Note: I used the original Code with the box, although it does not have any visual effect.
Code:
library(shiny)
library(shinydashboard)
ui = shinyUI(
navbarPage("Header",
tabPanel("home",
tags$head(tags$script(HTML('
var fakeClick = function(tabName) {
var dropdownList = document.getElementsByTagName("a");
for (var i = 0; i < dropdownList.length; i++) {
var link = dropdownList[i];
if(link.getAttribute("data-value") == tabName) {
link.click();
};
}
};
'))),
fluidPage(
fluidRow(box("this 1st box should lead me to tab1a", onclick = "fakeClick('tab1a')")),
fluidRow(box("this 2nd box should lead me to tab1b", onclick = "fakeClick('tab1b')")),
fluidRow(box("this 2nd box should lead me to tab2", onclick = "fakeClick('tab2')"))
)
),
navbarMenu("tab1",
tabPanel("tab1a", "Some Text inside Tab 1a."),
tabPanel("tab1b", "Some Text inside Tab 1b.")
),
tabPanel("tab2", "Some Text inside Tab 2.")
)
)
server = function(input, output, session){}
runApp(shinyApp(ui, server), launch.browser = TRUE)
Have fun!
I am trying to incorporate rchart based on nvd3 library in my html documentation generated by RMarkdown. But I am unable to adjust the height of the resulting iframe in my html document.
As a result of that only half of my plot is visible. is there any solution for this problem using R?. I don't know any html or css. Here is my code chunk producing the plot.
```{r, echo=FALSE,results='asis',comment=NA}
library(rCharts)
hair_eye_male <- subset(as.data.frame(HairEyeColor), Sex == "Male")
n1 <- nPlot(Freq ~ Hair, group = "Eye", data = hair_eye_male, type = "multiBarChart")
n1$show("iframesrc",cdn=TRUE)
```
I even tried opening the html file in text editor and editing the width and height options of Iframe in vain.