r - 在 Shiny 中单击按钮后如何打开新表单
问题描述
我是 Shiny 的新手,想知道在选择选项后如何打开/显示新表单。
在下面的示例中,如果我选择上传,那么我想打开/显示一个可以让我上传数据的表单,如果我选择分析数据,那么它将让我打开/显示一个让我分析数据的表单。
任何建议/帮助将不胜感激。
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
selectInput(inputId = "Task", label = "Select Task",choices = c("Please select","Upload","Analyze Data")),
textOutput("SR_Text")
)
# Define server logic required to draw a histogram
server <- function(input, output) {
observeEvent(input$Task, {
if(input$Task == "Upload"){
output$SR_Text<-renderText({
"Upload"
})
} else if (input$Task == "Analyze Data"){
output$SR_Text<-renderText({
"Analyze Data"
})
}
})
}
# Run the application
shinyApp(ui = ui, server = server)
解决方案
我想这conditionalPanel
就是你所需要的:
library(shiny)
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
column(3,
selectInput("Task", label = "Select Task",choices = c("Please select","Upload","Analyze Data"))
),
column(9,
conditionalPanel(
condition = "input.Task == 'Upload'",
fileInput("Upload", h3("File input Upload")),
selectInput(
"breaks", "Breaks",
c("Sturges",
"Scott",
"Freedman-Diaconis",
"[Custom]" = "custom")),
),
conditionalPanel(
condition = "input.Task == 'Analyze Data'",
sliderInput("breakCount", "Break Count", min=1, max=1000, value=10)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output,session) {
}
# Run the application
shinyApp(ui = ui, server = server)
推荐阅读
- python - 在 jupyter notebook 中运行带有超时的 python 脚本
- java - Android导航抽屉没有打开新的活动
- java - 如何将 TypeScript 日期转换为 Java 日期
- python - 从我的用户关注的用户那里获取所有帖子
- node.js - 无法解析带有双 apix 的字符串
- node.js - Docker 应用程序将无法工作,但如果不在 Docker 中,应用程序可以工作
- spring-boot - 使用 JPA 进行实体设计
- firebase - 如何在使用 Firebase 和 Flutter 登录和注册时发现身份验证错误?
- django - 保护 Django API 的最佳方法是什么?
- javascript - 在字符串上迭代相同的方法