【发布时间】:2018-08-08 00:18:11
【问题描述】:
我尝试在闪亮中创建动态框。 我们可以用 (status = "warning" or "info" etc.) 来改变盒子的状态(颜色) 我想根据选择输入的选择(动态)更改此框的颜色:
https://image.noelshack.com/fichiers/2018/32/2/1533638864-v1.png https://image.noelshack.com/fichiers/2018/32/2/1533638864-v2.png
代码如下所示:
SelectInput("s010102i", label = NULL,
choices = list("Value 1" = 1, "Value 2" = 2, "Value 3" = 3),
selected = 1) ,width = 12, background = "blue", status = "info")), column(4,
我们需要通过一个变量来改变状态中的“信息”。但是当我尝试将变量放在 ui 端时,它不起作用,当我像 output$s010102i 这样经过服务器时...状态不等于输出中的“信息”,而是:
ERROR: Invalid status: <div id="s010102o" class="shiny-html-output"></div>. Valid statuses are: primary, success, info, warning, danger.
我怎样才能动态放置它?以及如何改变一个变量的选择?
非常感谢!
编辑 -> 这里有一个可利用的代码来理解:
library(shiny)
library(shinydashboard)
library(DT)
# Define UI for application that draws a histogram
ui <- fluidPage(
dashboardPage(
dashboardHeader( title = "Simple Test"),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(title = h3("S.01.01.02", style = "display:inline; font-weight:bold"),
selectInput("s010102i", label = NULL,
choices = list("Not good" = 1, "O.K" = 2, "Good" = 3),
selected = 1) ,width = 12, background = "blue", status = renderUI("s010102o"))
# I want a text or a variable here
# Logically "danger", warning or success
# If Not good is selected, i wan that the status (the color) go to red (danger)
))))
# Define server logic required to draw a histogram
server <- function(input, output) {
statut = c("danger","warning","success")
output$s010102o <- reactive({
valueStatut = input$s010102i # Give 1 2 or 3
s010102o = statut[valueStatut] # give the value of the statut if "danger" the box changes to red
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】:
-
renderUI 可能会有所帮助。
-
感谢您的回答。但我有这个错误:“错误:'匹配'需要向量参数”。匹配?
-
上面测试的代码。再次感谢。错误是一样的:renderUI("s010102o") 应该是 1,2 或 3 才能工作,但我想要一个变量 :)
-
理想情况下,我们需要
updateBox,并且在 GitHub 上提交了一个问题:github.com/rstudio/shinydashboard/issues/287
标签: css r web-applications shiny shinydashboard