【发布时间】:2021-05-18 12:49:25
【问题描述】:
我正在尝试使用用户输入生成条形图。我尝试在输入之前使用~,但它不起作用。我看到的是带有轴标签的空白画布。
代码
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)
【问题讨论】: