简体   繁体   中英

How to open a new form after clicking a button in Shiny

I am new to Shiny and would like to know how would I open / display a new form after selecting an option.

In the example below, if I select Upload, then I would like to open / display a form that would let me upload the data and if I select Analyze Data then it would let me open / display a form that would let me Analyze Data.

Any advice / help would be appreciated.

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)

I think conditionalPanel is all you need:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM