B. Davis
B. Davis

Reputation: 3441

change dimensions of shiny app embedded in r markdown HTML

I have an embedded shiny app within an r markdown script which is knit to HTML. Currently when I knit the r markdown chunk that contains the shiny app, the app is not shown in the full size. r markdown includes the shiny app within a smaller 'window' where I need to use a window slider/scroller to view the entire app.

I think this is an r markdown issue and have tried to change the chunk dimensions with fig.width and fig.height, but to no avail.

I want the shiny app to be shown in the full extent where I can view the entire plot and the included slider bar in a single view.

Any suggestions would be appreciated. A reproducible r markdown script is provided below with data included from dput. Any suggestions would be greatly appreciated.

---
output: html_document
runtime: shiny
---

```{r Packages, include=FALSE}
library(ggplot2)
library(shiny)
```


```{r Data, include=FALSE}
dat <- structure(list(AcquisitionStartTime = structure(c(1L, 2L, 5L, 
6L, 8L, 9L, 10L, 12L, 13L, 14L, 15L), .Label = c("2013.02.09 00:00:00", 
"2013.02.09 06:00:00", "2013.02.09 12:00:00", "2013.02.09 18:00:00", 
"2013.02.10 00:00:00", "2013.02.10 06:00:00", "2013.02.10 12:00:00", 
"2013.02.10 18:00:00", "2013.02.11 00:00:00", "2013.02.11 06:00:00", 
"2013.02.11 12:00:00", "2013.02.11 18:00:00", "2013.02.12 00:00:00", 
"2013.02.12 06:00:00", "2013.02.12 12:00:00"), class = "factor"), 
    GPSUTMNorthing = c(4947787L, 4947945L, 4947957L, 4947954L, 
    4947797L, 4947835L, 4947825L, 4947784L, 4947842L, 4947839L, 
    4947789L), GPSUTMEasting = c(600201L, 600910L, 600911L, 600907L, 
    601052L, 601038L, 601031L, 601066L, 600998L, 600995L, 601058L
    )), .Names = c("AcquisitionStartTime", "GPSUTMNorthing", 
"GPSUTMEasting"), row.names = c(1L, 2L, 5L, 6L, 8L, 9L, 10L, 
12L, 13L, 14L, 15L), class = "data.frame")
```



```{r Time, include=FALSE}
dat$PosiGMT <- as.POSIXct(strptime(as.character(dat$AcquisitionStartTime),"%Y.%m.%d %H:%M:%S"))
```

### Header One: 
Headers, text, and figures here...


### Interactive shinyApp
```{r, echo = FALSE, fig.height=6}
shinyApp(
ui <- fluidPage(
          titlePanel("GPS Data Summary"),
          sliderInput(inputId = "Date",
                  label = "Sequance of Observations",  
                  min = as.Date(min(dat$PosiGMT)), max = as.Date(max(dat$PosiGMT)),
                  value = as.Date(min(dat$PosiGMT))),
                  #animate = animationOptions(interval=75, loop=T)),
          plotOutput("PointPlot")
            ),

server <- function(input, output) {
            output$PointPlot <- renderPlot({
              p <- ggplot(dat[as.Date(dat$PosiGMT) <= input$Date ,], 
                          (aes(x = GPSUTMEasting, y = GPSUTMNorthing ))) + 
                geom_point() + geom_path() + 
                xlim( min(dat$GPSUTMEasting), max(dat$GPSUTMEasting))+
                ylim( min(dat$GPSUTMNorthing), max(dat$GPSUTMNorthing))
              print(p)
              })
}

)
```


### More headers below 
More text and figures here...    

Upvotes: 4

Views: 2345

Answers (1)

Xiongbing Jin
Xiongbing Jin

Reputation: 12087

The height of embedded Shiny app is controlled by adding

options = list(height = 500)

right before the closing parenthesis. i.e.

    ....
    ylim(min(dat$GPSUTMNorthing), max(dat$GPSUTMNorthing))
    print(p)
  })
},      
options = list(height = 600)      
)
```

Don't forget the , before this added line.

Upvotes: 9

Related Questions