r - 禁用文件输入
问题描述
我的闪亮应用程序中有一个selectizeInput
和一个。fileInput
我想保持fileInput
禁用状态,直到未在selectizeInput
.
此外,我希望每次用户单击时都会弹出一条消息fileInput
来选择一个值。我怎样才能做到这一点。
解决方案
正如其他人所提到的,该shinyjs
软件包在这里很有用。您可以使用enable
,disable
或toggleState
.
library(shiny)
library(shinyjs)
ui = fluidPage(
shinyjs::useShinyjs(),
selectizeInput("selector", label="Choose 2:", multiple=TRUE,
choices=letters[1:5], selected=letters[1:5]),
fileInput("file_inputer", label="upload file")#,
# dataTableOutput('table')
)
server = function(input, output) {
observe({
shinyjs::toggleState("file_inputer", length(input$selector) %in% 0:4)
})
observeEvent(input$file_inputer, {
showModal(modalDialog(
title="Do you want a header row?",
selectInput("option_selector", label="Choose an option",
choices=c("option 1", "option 2", "option 3")),
footer = tagList(actionButton("read_file", "Read File"),
modalButton("Cancel")
)
))
})
observeEvent(input$read_file, {
# do something with your option value
removeModal()
})
}
# Run the application
shinyApp(ui = ui, server = server)
推荐阅读
- ios - 使用 DarkMode,触摸时不会选择单元格的 ContentView,只有 AccessoryView
- typescript - 检查 VSCode 中嵌套的 TypeScript 接口和类型
- android - 如何添加窗口消息事件监听器 - Android WebView
- php - Swagger 基本身份验证失败,使用 php 客户端
- java - 如何在调用 API 中保存价值 Intent?
- jenkins - 如何为原生移动应用程序的 Junit 项目集成 Jenkins?
- gradle - Gradle maven publish 生成具有重复属性的无效 POM
- python - 是否可以将 SpaCy 安装到 Raspberry Pi 4 Raspbian Buster
- javascript - 使用 NodeJS 完成 AJAX 请求时页面重新加载
- javascript - 在 Javascript(节点 js)中,如何知道特定字符串在其他字符串中?