单击Shiny中的按钮后如何打开新表单

时间:2020-05-14 18:56:28

标签: 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)

1 个答案:

答案 0 :(得分:1)

我认为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)