【发布时间】:2016-09-07 19:54:12
【问题描述】:
我希望应用使用默认值加载一次,但只有在用户输入正确密码时才会响应。为简单起见,让我们使用 Rstudio 模板(经过精心编辑):
ui.R:
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
passwordInput("pw", "Password:"),
sliderInput("nbins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
mainPanel(
plotOutput("histo")
)
)))
server.R:
PASSWORD <- "test"
library(shiny)
shinyServer(function(input, output) {
output$histo <- renderPlot({
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$nbins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
有两个反应输入 pw 和 nbins。我的问题是:如何扩展代码以使 nbins(行为)在 reactive 和 non-reactive 之间切换,具体取决于输入 pw 等于 @ 987654327@?
【问题讨论】:
-
conditionalPanel()是您要找的吗? -
@VanceLopez 谢谢,但不,我正在寻找如何在服务器端执行此操作。如果那是可能的。您将如何使用
conditionalPanel()解决此问题? -
我想我不确定您所说的“在反应式和非反应式之间切换”是什么意思。您是否要阻止用户与
nbins交互,除非他们拥有正确的密码,但仍希望根据输入的原始值显示output$histo? -
@VanceLopez 完全正确!
标签: r reactive-programming shiny