[英]r shiny user input based on choice
我知道如何在UI上添加文本输入或单选按钮或日期输入,我想做的是问用户是否要输入文本或日期范围? 根据用户选择的内容,显示文本输入还是日期输入。 不确定如何执行此操作。
Pseudo Code
1) Please choose if you want to enter text or date range.
Radio Button 1 - Text Input
Radio Button 2 - Date Range
2a) If the user chooses Radio Button 1, then Text Input should be displayed on the main panel, option to enter two dates (From & to) should not be displayed
2b) If the user chooses Ratio Button 2, then the option to enter two dates (From & to) should be displayed on the Main panel and text input should not be displayed.
不确定如何执行此操作。 需要一些指针。
我在这里感到很慷慨,通常您应该提供尝试的代码,但这是如何有条件输入的有效示例。
library(shiny)
runApp(
list(
ui = pageWithSidebar(
headerPanel("Option Input via Radio Buttons"),
sidebarPanel(
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Date" = "date", "Text" = "text"),
selected = 1),
uiOutput("textORdate")
),
mainPanel()
),
server = function(input, output){
output$textORdate <- renderUI({
validate(
need(!is.null(input$radio), "please select a input type")
)
if(input$radio == "text"){
textInput("mytext", "Text Input", "please enter text")
}else{
dateRangeInput("daterange", "Date range:",
start = "2012-01-01",
end = "2015-03-06")
}
})
}))
我在这里演示了多个概念。 首先,您可以通过在server.R部分中创建输入来创建动态输入。 然后由uiOutput
显示。 其次,我总是喜欢介绍人们进行validate
。 这是一项重要功能,可帮助排除故障或为用户提供有用的错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.