Deleted:From two selectInputs in the server, how to make one dependent on another? (Rshiny)
0
0
Entering edit mode
4.1 years ago
ev97 ▴ 40

Hi everyone,

I have two select inputs. The main one: Dataset, which have 2 options: 1) Cars and 2) Iris. The other select input, it has information from the Cars' dataset and information from the Iris one.

I need to show the information from Cars if I select Cars and the information from Iris if I select Iris.

Now, my code is not able to do that. Simply it shows you the options to choose the datasets but in the second select input only shows the information from Cars.

I don't know how to do it, I have been a lot of posts but I couldn't get what I want. For example this post Filter one selectInput based on selection from another selectInput? was very similar and I thought that I could do something similar, but he doesn't use a dataset from R...

My code:

library(shiny)
    ui <- fluidPage(

      titlePanel("Select a dataset"),

      sidebarLayout(
        sidebarPanel(
          selectInput("dataset", "Dataset",
                      choices = c("Cars" = "Cars", "Iris" = "Iris")),
          uiOutput("select_cars"),
          uiOutput("select_iris")

        ),

        mainPanel(
          verbatimTextOutput("text"),
          verbatimTextOutput("text2") 
        )
      )
    )

    server <- function(input, output) {

      cars <- reactive({
        data("mtcars")
        cars <- rownames(mtcars)
        return(cars)
      })

      iris <- reactive({
        data("iris")
        iris <- data.frame(unique(iris$Species))
        colnames(iris) <- "iris"
        return(iris)
      })

      output$select_cars <- renderUI({
        selectInput(inputId = "options_cars", "Select one", choices = cars())
      })

      output$select_iris <- renderUI({
        selectInput(inputId = "options_iris", "Select one iris", choices = iris())
      })

      output$text <- renderPrint(input$options_cars)
      output$text2 <- renderPrint(input$options_iris)
    }

    #Run the app
    shinyApp(ui = ui, server = server)

On the other hand I get an error: object of type ‘closure’ is not subsettable. But I don't know why.

Finally, I apologize if someone has already asked something similar before, I really have been looking all morning and I do not know how to solve it. (I am quite new at Shiny and I am trying to do my best). Also this is my first post in Biostars, so sorry if I have done something wrong.

Thanks very much in advance,

Regards

reactive shiny selectInput R Rshiny • 878 views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1677 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6