I'm trying to generate a bar chart with user inputs. I tried using ~
before the inputs but it doesn't work. What I'm seeing is a blank canvas with the axis labels.
Code
library(shiny)
library(plotly)
ui <- fluidPage(
titlePanel(tags$h4("Bar Chart")),
sidebarLayout(
sidebarPanel(selectInput("input1", label = NULL, choices = names(mtcars)),
selectInput("input2", label = NULL, choices = names(mtcars))),
mainPanel(plotlyOutput("bar"))
)
)
server <- function(input, output, session) {
output$bar <- renderPlotly(
mtcars %>%
plot_ly(
x = ~input$input1,
y = ~input$input2,
type = "bar"
)
)
}
shinyApp(ui, server)