0

This is a simplified version of the problem I have. I want the SelectInput to allow selection of different columns, which will then be the y axis on the plot.I have used the aes_string function as suggested in similar question but it did not work. Thankful for help

df <-data.frame(name = c("john", "mary"), age = c(9, 10), pets =  c(20, 30))
library(ggplot2)

ui <- fluidPage(
    
    # Application title
    titlePanel("name and number of pets"),
    
    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            box(width = 15,
                selectInput(inputId = "select_variable", label = "Selecione a variável para consulta", 
                            choices = c("age", "pets"), 
                            selected = 1))
        ),
        
        # Show a plot of the generated distribution
        mainPanel(
            plotOutput(outputId = "a")
        )
    )
)

server <- function(input, output) {
    
    output$a <- renderPlot({
        
        
        ggplot(df)+
            geom_bar(mapping = aes_string(x="name", y = input$select_variable), stat = "identity")
        
    })
}

shinyApp(ui = ui, server = server)
0

1 Answer 1

1

You're trying to mix shinydashboard (box) with standard shiny without loading the shinydashboardpackage. Hence, the call to box tries to run graphics::box(). [It would have been helpful to provide the error message rather than simply saying "It did not work".]

The solution is either to delete the call to box or to load shinydashboard.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.