【发布时间】:2017-01-26 23:36:05
【问题描述】:
下面是我的shiny 应用程序的简化版本。我查看了shinyjs 包中的一些示例,但没有找到任何可以帮助我的东西。
如果上传的数据框之一(在我的真实示例中)或选择的数据框之一具有特定的列名称(下例中的第 3 列),我想禁用 Submit button。
这可以用shinyjs 完成吗?
library(rhandsontable)
library(shiny)
library(shinyjs)
df1 <- data.frame(col1 = rnorm(20),
col2 = rep(T, 20))
df2 <- data.frame(col1 = rnorm(20),
col2 = rep(F, 20),
col3 = rnorm(20))
server <- function(input, output) {
values = reactiveValues()
values[["df1"]] <- df1
values[["df2"]] <- df2
df <- reactive({
if (input$df == "df1") {
df <- values[["df1"]]
} else {
df <- values[["df2"]]
}
df
})
observeEvent(input$Submit, {
shinyjs::alert("Thank you!")
})
#observe({
# if (is.null(input$df) || input$df == "df1") {
# shinyjs::disable("submit")
#} else {
# shinyjs::enable("submit")
#}
#})
output$out <- renderRHandsontable({
hot <- rhandsontable(df())
hot
})
}
ui <- fluidPage(
shinyjs::useShinyjs(),
sidebarLayout(sidebarPanel(
selectInput(
'df', 'Select data.frame:',
choices = c('df1', 'df2'),
selected = 'df1'
),
actionButton("Submit", label = "Submit")
),
mainPanel(rHandsontableOutput("out"))))
shinyApp(ui = ui, server = server)
【问题讨论】:
-
仅供参考:您的代码在复制时对我抛出错误:
Error in tag("form", list(...)) : argument is missing, with no default -
@Tonio Liebrand。我刚刚打开了一个新的 R 会话并毫无问题地运行了代码。
-
哦,对不起,清除环境后它起作用了。