Ankush
1
Hi all,
I want to read data from an excel. Data is like this-
.
I want to write a program which flows sequentially. Like in the example-
- If I select India, it should show the cities.
- If I select New Delhi as city it should show the subsequent popular item
- If I select popular item, it should show the subsequent rating.
How can I do this?
You can use selectInput to select the entries from the list and updateSelectInput to update the selections based on the selection made a level up.
library(shiny)
library(tidyverse)
ui <- fluidPage(
titlePanel("Multiple selection demo"),
# Sidebar
sidebarLayout(
sidebarPanel(
selectInput("manufacturer", "select a manufacturer", choices = unique(mpg$manufacturer)),
selectInput("model", "select a model",
choices = NULL, selected = NULL),
selectInput("trans", "select a transmission",
choices = NULL, selected = NULL)
),
# MainPanel
mainPanel(
tableOutput("results_table"))
))
# server
server <- function(input, output, session) {
observeEvent(input$manufacturer, {
updateSelectInput(session = session, inputId = "model",
choices = unique(filter(mpg, manufacturer == input$manufacturer)$model),
selected = "")
})
observeEvent(c(input$model, input$manufacturer), {
updateSelectInput(session = session, inputId = "trans",
choices = unique(filter(mpg, model == input$model)$trans),
selected = "")
})
#calculate the results
results = reactive({
req(input$manufacturer)
req(input$model)
req(input$trans)
filter(mpg, manufacturer == input$manufacturer &
model == input$model &
trans == input$trans)
})
#show the results as an table
output$results_table = renderTable({
req(results())
results()
})
}
# Run the application
shinyApp(ui = ui, server = server)
Ankush
3
Hi Matthias,
It works.
But what if incase of selectInput, you have action buttons?
system
Closed
4
This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.