【发布时间】:2019-12-20 00:54:55
【问题描述】:
当multiple = TRUE 时,我似乎无法弄清楚如何在 flexdashboard/shiny 中更改数据框中列的值。在下面的示例中,我可以通过单独选择 x 和 y 来更改它们。我想要完成的是当我同时选择 x 和 y 时,df$x 变为 3,df$y 变为 2。
但是当两者都被选中时,只有第一个被选中的会被改变。
---
title: "Test"
output:
flexdashboard::flex_dashboard:
orientation: columns
social: menu
source_code: embed
runtime: shiny
---
```
library(flexdashboard)
library(shiny)
library(DT)
df <- data.frame(
x = 1:10,
y = 1:10)
selectInput("var", label = "Change:",
choices = list("no change", "x","y"),
multiple =TRUE,
selected = "no change"
)
renderDataTable({
if(input$var == "no change") {df <- df}
if(input$var %in% "x") {df$x <- 3}
if(input$var %in% "y") {df$y <- 2}
return(df)
})
```
任何帮助将不胜感激。
【问题讨论】: