从单选按钮或 shiny/flexdashboard 中的自由文本输入
Input from radio buttons or free text in shiny/flexdashboard
我正在尝试允许用户使用单选按钮输入变量,同时提供自由文本选项(如果列出的对象中的 none 符合所需的输入)。我无法通过在线搜索找到方法。我还是 flexdashboard/shiny 的新手。
我在下面创建了这个代表。我想要做的是添加第四个具有自由文本选项的单选按钮。有什么建议吗?
谢谢
---
title: "example2"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
radioButtons("nm", "What is your name??",
c("jo" = "John",
"pe" = "Peter",
"da" = "David"))
actionButton("execute", "enter")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
phrase = eventReactive(input$execute, {
paste("Hi", input$nm, sep=" ")
})
renderText({
req(phrase())
phrase()
})
```
您可以使用 updateRadioButtons
更新单选按钮选项:
choices = c( "jo"="John",
"pe"="Peter",
"da"="David")
radioButtons("nm", "What is your name??", choices)
textInput("other", "other")
observeEvent(input$other, {
if(!is.null(input$other) && input$other != "")
updateRadioButtons(session, "nm", choices = c(choices, input$other),
selected = input$other)})
actionButton("execute", "enter")
我正在尝试允许用户使用单选按钮输入变量,同时提供自由文本选项(如果列出的对象中的 none 符合所需的输入)。我无法通过在线搜索找到方法。我还是 flexdashboard/shiny 的新手。
我在下面创建了这个代表。我想要做的是添加第四个具有自由文本选项的单选按钮。有什么建议吗?
谢谢
---
title: "example2"
runtime: shiny
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: fill
---
```{r setup, include=FALSE}
library(flexdashboard)
```
Column {data-width=650}
-----------------------------------------------------------------------
### Chart A
```{r}
radioButtons("nm", "What is your name??",
c("jo" = "John",
"pe" = "Peter",
"da" = "David"))
actionButton("execute", "enter")
```
Column {data-width=350}
-----------------------------------------------------------------------
### Chart B
```{r}
phrase = eventReactive(input$execute, {
paste("Hi", input$nm, sep=" ")
})
renderText({
req(phrase())
phrase()
})
```
您可以使用 updateRadioButtons
更新单选按钮选项:
choices = c( "jo"="John",
"pe"="Peter",
"da"="David")
radioButtons("nm", "What is your name??", choices)
textInput("other", "other")
observeEvent(input$other, {
if(!is.null(input$other) && input$other != "")
updateRadioButtons(session, "nm", choices = c(choices, input$other),
selected = input$other)})
actionButton("execute", "enter")