'selectizeInput'당 x 축을 ggplot
으로 선택할 수있는 반짝이는 앱을 만들려고했습니다.Shiny : ggplot2에서 동적으로 사용되는 열을 변경하십시오.
나는 Gallery Example에 대해 알고 있는데, 이것은 원하는 열을 사전 선택하여 해결되었습니다. 왜냐하면 제 경우에는 데이터 구조가 속성을 aes()
에 동적으로 변경할 수있을 때 데이터 구조가 조금 복잡하기 때문입니다.
더 나은 이해를 위해 최소한의 작업 예제를 추가했습니다. 불행히도 ggplot
은 해당 열을 사용하는 대신 입력 값을 값으로 사용합니다.
library(shiny)
library(ggplot2)
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
# Application title
titlePanel("Select x Axis"),
sidebarLayout(
sidebarPanel(
selectizeInput("xaxis",
label = "x-Axis",
choices = c("carat", "depth", "table"))
),
mainPanel(
plotOutput("Plot")
)
)
))
server <- shinyServer(function(input, output) {
output$Plot <- renderPlot({
p <- ggplot(diamonds, aes(x = input$xaxis, y = price))
p <-p + geom_point()
print(p)
})
})
# Run the application
shinyApp(ui = ui, server = server)
'aes_' 또는'aes_string'을 사용하십시오. '? aes_'를 참조하십시오. 그것은'ggplot (diamonds, aes_string (x = 입력 $ xaxis, y = '가격'))'이 될 것입니다. – Axeman
완벽하게 작동하고,'aes _()'에 대해서는 kown을하지 않았습니다. 응답자로 게시하는 경우 올바른 것으로 표시합니다. 고맙습니다. – WitheShadow