1
我有一個不同列的數據框,我想繪製,但是我在Shiny中創建了一個複選框來指示我想要繪製哪些。如何在我的ggvis代碼中使用條件?
UI.R
tabPanel('Data Insights',
mainPanel(
ggvisOutput("plot4"),
fluidRow(
checkboxGroupInput('investcheck', 'Investment',
choices = c('OOH', 'PRINT', 'TV', 'DIGITAL'),
selected=c('TV')))
)
)
SERVER.R
reactive({
if(is.element('PRINT', input$investcheck)) {oprint=1} else {oprint=0}
if(is.element('OOH', input$investcheck)) {oooh=1} else {oooh=0}
if(is.element('TV', input$investcheck)) {otv=1} else {otv=0}
if(is.element('DIGITAL', input$investcheck)) {odigital=1} else {odigital=0}
plt <- df_sales %>% ggvis(~sales) %>%
if(oprint==1) {
plt <- plt %>%
layer_points(data = df_sales, x = ~sales, y = ~PRINT_Investment, fill:='3498DB')
} else{
plt <- plt %>%
layer_points(data = df_sales, x = ~sales, y = ~PRINT_Investment, fill:='3498DB')
}
plt
}) %>% bind_shiny("plot4")
但我始終有一個錯誤:
Warning in if (.) oprint == 1 else { :
the condition has length > 1 and only the first element will be used
Error in if (.) oprint == 1 else { :
argument is not interpretable as logical