I have a data frame that contains the following columns. Partner & Contact Person.
Partner <- c("Google", "Microsoft", "Apple","Amazon")
ContactPerson <- c("Andrew","Mary","John","Barbara")
DF <- data.frame(Partner, ContactPerson)
# Create a variable called Partner Organisation
PartnerOrg <- DF$Partner
In flexdashboard, I'd like a dynamic functionality, such that when a person selects Google under the as a selectInput function, a render outbox output of Andrew appears below the dropdown menu. Below is the code in my rmd
file in the sidebar of my flexdashboard
selectInput(
"Select", label = h5("Select partner organisation"),
choices= PartnerOrg,
hr(),
fluidRow(column(3, verbatimTextOutput("value")))
)
function(input, output) {
# You can access the value of the widget with input$select, e.g.
output$value <- renderPrint({ input$select })
}
When I run the rmd file to load the dashboard, I get an error "Error: argument is not interpretable as logical"
How do I go about this?
CodePudding user response:
The issue is that you wrapped the UI code to add the verbatimTextOutput("value")
inside selectInput
, i.e. hr()
is passed to the selected
argument and fluidRow(column(3, verbatimTextOutput("value")))
to the multiple
argument. I can only guess that you get the error as the latter requires a logical
. When I use your code I get an error
Error in if (multiple) selectTag$attribs$multiple <- "multiple" : the condition has length > 1
instead, but for the same reason.
To fix your issue move the UI code outside of selectInput
as I do in the minimal reprex below:
---
title: "FOO"
output: flexdashboard::flex_dashboard
runtime: shiny
---
```{r global, include=FALSE}
Partner <- c("Google", "Microsoft", "Apple","Amazon")
ContactPerson <- c("Andrew","Mary","John","Barbara")
DF <- data.frame(Partner, ContactPerson)
# Create a variable called Partner Organisation
PartnerOrg <- DF$Partner
```
Column {.sidebar}
-----------------------------------------------------------------------
```{r}
selectInput(
"Select", label = h5("Select partner organisation"),
choices = PartnerOrg
)
verbatimTextOutput("value")
```
```{r}
output$value <- renderText({
subset(DF, Partner %in% input$Select, "ContactPerson", drop = TRUE)
})
```
UPDATE To set text color and the font weight of the text output you could add the below chunk of CSS
code to your rmd. For more on styling or theming a flexdashboard
document see https://rstudio.github.io/flexdashboard/articles/theme.html#add-css-styles-1.
```{css}
.shiny-text-output {
color: #da70d6;
font-weight: bold
}
```