Flexdashboard columns - text not showing up - r

In my flexdashboard I have a column with a note, then a table, and I would like to add one more note below the table. But I am struggling to get the second note to show up. I can make a new header there but I really just want another sentence that shows up without a new header. Here is some simple code to illustrate. Thanks!
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: scroll
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(shiny)
library(rhandsontable)
df <- tibble(
`Col 1` = seq(1,24,1), `Col 2` = " ")
```
Column {data-width=650}
-----------------------------------------------------------------------
### Table
I can write a note here
```{r}
output$table_exer <- renderRHandsontable({
rhandsontable(df, rowHeaders = NULL)
})
rHandsontableOutput("table_exer")
```
But I also want a note here
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
```
### Chart C
```{r}
```

very simple, wrap your table inside fluidRow, like this:
```{r}
output$table_exer <- renderRHandsontable({
rhandsontable(df, rowHeaders = NULL)
})
fluidRow(rHandsontableOutput("table_exer"))
```
To make the margin and spacing look nicer, we can also do following:
```{r}
output$table_exer <- renderRHandsontable({
rhandsontable(df, rowHeaders = NULL)
})
column(12, fluidRow(rHandsontableOutput("table_exer")))
br()
```

Related

How to use shiny inputpael to filter my dataframe by a category in a column? Rshiny and RMarkdown

I'm trying to make a simple shiny app where I can select an input of cylinders(4,6, or 8) and then generate a table with the cars who are either 4,6, or 8 cylinders.
This is my code
---
title: "Test Dash"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
Inputs {.sidebar data-width=300}
=====================================
$$\\[.01in]$$
```{r pressure, echo=FALSE, out.width = '100%'}
library(readr)
library(shiny)
library(DT)
```
```{r}
cylinder <- mtcars$cyl
selectInput("my_dropdown", label = "Select Cylinders:", choices = cylinder)
```
# Overview
Column {data-width=750}
-----------------------------------------------------------------------
### Table
```{r}
renderDataTable(
datatable(mtcars[input$my_dropdown,]
)
)
```
i'm able to generate the input and an empty table but the table does not update when I choose a cylinder.
Here is a screenshot.
Any idea how I can fix this?
mtcars2 <- reactive({
mtcars[mtcars$cyl == input$my_dropdown,]
})
renderDataTable(
datatable(mtcars2())
)
)

Input menu contents do not overflow row box in flexdashboard

I am creating a reactive dashboard using flexdashboard with shiny. I would like the first row below the header to contain two separate selectInput() menus. I am keeping the height of the rows small (50), because there will be several more graphs underneath and I need the space. However, when the dashboard is rendered, clicking on the input menu to select another option results in the dropdown "disappearing" behind the row (not overflowing it). This makes it difficult to select items below the second or third element. How do I make the contents overflow? Here is a reproducible code + screenshot:
---
title: "Test Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```
Row {data-height=50}
-----------------------------------------------------------------------
### Window 1
```{r}
selectInput("project", label = NULL, choices = c("A","B","C","D"))
```
### Window 2
```{r}
selectInput("data", label = NULL, choices = c("1","2","3","4","5", "6"))
```
Row
-----------------------------------------------------------------------
### Chart B
```{r}
renderPlot({
plot(rnorm(1000), type = "l", main = paste("Project:",input$project, " Data:", input$data))
})
```
Attached an image of how it looks.
Flexdasboard image:
Thanks much,
Jorge
You said there will be more graphs in the future, but I think you can render the individual plots 'underneath' Flexdashboard, to save space. I changed, the rows to columns, let me know.
---
title: "Test Dashboard"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```
Column {data-width=600}
-----------------------------------------------------------------------
### Window 1
```{r}
selectInput("project", label = NULL, choices = c("A","B","C","D"))
```
### Window 2
```{r}
selectInput("data", label = NULL, choices = c("1","2","3","4","5", "6"))
```
Column {data-width=400}
-----------------------------------------------------------------------
### Chart B
```{r}
renderPlot({
plot(rnorm(1000), type = "l", main = paste("Project:",input$project, " Data:", input$data))
})
```

Embed a website in shiny app using flexdashboard: not working, not reactive

I am trying to make a shinyapp using flexdashboard. The app takes as input a string of text, and then it outputs a website using that input text. I have an example of the app working in standard shiny. My problem is "translating" it to an app using flexdashboard.
Here is my app in standard shiny:
library(shiny)
ui <- fluidPage(titlePanel("Testing"),
sidebarLayout(
sidebarPanel(
fluidRow(
column(9, selectInput("Color", label=h5("Choose a color"),choices=c('red', 'blue'))
))),
mainPanel(fluidRow(
htmlOutput("frame")
)
)
))
server <- function(input, output) {
observe({
query <- input$Color
test <<- paste0("https://en.wikipedia.org/wiki/",query)
})
output$frame <- renderUI({
input$Color
my_test <- tags$iframe(src=test, height=600, width=535, frameborder = "no")
print(my_test)
my_test
})
}
shinyApp(ui, server)
Here is my attempt trying to get it to work using flexdashboards. I am having problem trying to get the input as a reactive expression to make my output dynamic. I am trying 2 different ways to get the output, but none work.
---
title: "Testing Colors"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
lookup <- structure(c("r", "b"), .Names = c("Red", "Blue"))
Column {.sidebar}
-----------------------------------------------------------------------
```{r}
selectInput('Color', label = 'Select a color', choices = lookup, selected = "r")
Column {data-width=600}
-----------------------------------------------------------------------
### Color Web Page
```{r}
observeEvent(input$Color,{
output$url <-renderUI(a(href=paste0("https://en.wikipedia.org/wiki/", input$Color)))
})
Column {data-width=400}
-----------------------------------------------------------------------
### Another webpage
```{r}
selectedColor<- reactive({
color <- input$Color
})
webpage <- renderUI({
include_url(paste0("https://www.wikipedia.org/",selectedColor))
})
webpage
I would certainly appreciate any comments or ideas.
Thanks!
This code gave me a flexdashboard back with the selectInput, I think the alignment of spaces made for errors
---
title: "Testing Colors"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup, include=FALSE}
library(flexdashboard)
library(knitr)
lookup <- structure(c("r", "b"), .Names = c("Red", "Blue"))
```
```{r,}
selectInput('Color', label = 'Select a color', choices = lookup, selected = "r")
```
Column {data-width=600}
-----------------------------------------------------------------------
### Color Web Page
```{r}
observeEvent(input$Color,{
output$url <-renderUI(a(href=paste0("https://en.wikipedia.org/wiki/", input$Color)))
})
```
Column {data-width=400}
-----------------------------------------------------------------------
### Another webpage
```{r}
selectedColor<- reactive({
color <- input$Color
})
webpage <- renderUI({
include_url(paste0("https://www.wikipedia.org/",selectedColor))
})
webpage

Plotting after Checking the radio Button and Pressing action Button

I have a dataframe, please help me in executing this. The moment I check "HoltWinters" and press "Execute" button, dataframe "HW" should appear. I have tried half way. But need anyone help here please................................
---
title: "Untitled"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
---
library(flexdashboard)
library(readxl)
library(tidyverse)
library(shiny)
library(rhandsontable)
library(dplyr)
library(forecast)
library(fpp)
library("TTR")
x <- c(1:123)
x <- ts(x, start = c(2017, 23), end = c(2019, 39), frequency = 53)
x.hw <- HoltWinters(x)
HW <- forecast(x.hw, h = 6)
HW <- as.data.frame(HW)
Model Execution
Inputs {.sidebar}
radioButtons("r",h5("Models"),choices = list("Regression", "Arima","HoltWinters","Model4","Model5"),selected = "No", inline = F)
actionButton("a","Execute",icon = NULL)
Row {.tabset .tabset-fade}
HoltWinters
output$table1 <- renderRHandsontable({
eventReactive(input$a,{
rhandsontable(HW)
})
})
rHandsontableOutput("table1")
You should not use eventReactive but observeEvent instead (check here). Also, this condition should be outside of the output part: "if I observe this event, then I will display this table" (and not "I will display this table and then fill it according to which button is ticked").
Here's the solution to your problem (you should customize it so that just selecting HoltWinters displays the table but at least you have a working basis here):
---
title: "Untitled"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(readxl)
library(tidyverse)
library(shiny)
library(rhandsontable)
library(dplyr)
library(forecast)
library(fpp)
library(TTR)
```
```{r}
x <- c(1:123)
x <- ts(x, start = c(2017, 23), end = c(2019, 39), frequency = 53)
x.hw <- HoltWinters(x)
HW <- forecast(x.hw, h = 6)
HW <- as.data.frame(HW)
```
Model Execution
=================
Inputs {.sidebar}
-----------------------------------------------------------------------
```{r}
radioButtons("r",h5("Models"),choices = list("Regression", "Arima","HoltWinters","Model4","Model5"),selected = "No", inline = F)
actionButton("a","Execute",icon = NULL)
```
Row {.tabset .tabset-fade}
-------------------------------------
### HoltWinters
```{r}
observeEvent(input$a,{
output$table1 <- renderRHandsontable({
rhandsontable(HW)
})
})
rHandsontableOutput("table1")
```
Edit: you can add a condition within the observeEvent so that the table is displayed only if HoltWinters is ticked:
observeEvent(input$a,{
if (input$r == "HoltWinters") {
output$table1 <- renderRHandsontable({
rhandsontable(HW)
})
}
else {
output$table1 <- renderRHandsontable({
})
}
})
rHandsontableOutput("table1")

Using plot_click in flexdashboard

Is there a way to have plots with mouse interactions using flexdashboard?
In shiny this is not difficult. I want to save mouse clicks, and in shiny UI I would use:
mainPanel(plotOutput("scatterplot", click = "plot_click"))
And in the server you would have:
df <- reactiveValues(Clicksdf = data.frame(clickx = numeric(), clicky = numeric()))
Can I do this in flexdashboard?
Write the code chunk as if it were both the Shiny UI and server:
---
title: "Untitled"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
plotOutput("plot1", click = "wt")
output$plot1 <- renderPlot({
plot(mtcars$mpg ~ mtcars$wt)
})
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
renderText({
unlist(input$wt$x)
})
```

Resources