Black Lives Matter. Please consider donating to Black Girls Code today.

How do I fix my update buttons? (Codes and graphs attached)

Hello there, I am trying to make a graph to show the export and import of a certain commodity good with a bar chart of the trade balance on the side.

When I click ‘export’ on the update button, the bar chart will show perfectly. However, when I click ’ import’, the bars will disappear.

Could you tell me how to fix

this issue?

Here are my codes:

data <- import(‘data.csv’)

data$Exports <- as.numeric(data$Exports)
data$Trade Balance <- as.numeric(data$Trade Balance)

l <- data %>%
group_by(Countries) %>%
plot_ly(labels = ~ Countries, values = ~Exports, type = “pie”,
showlegend = FALSE,
domain = list(x = c(0.55, 1), y = c(0.0, 1)))%>%
layout(title = “Export”,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE, showline = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE, showline = FALSE)

)%>%
add_pie(labels = ~ Countries, values = ~Imports, textposition = “inside”,
showlegend = FALSE, visible = F,

     domain = list(x = c(0.55, 1), y = c(0.0, 1))) %>%

layout(title = “Import”, showlegend = FALSE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE, showline = FALSE, title = “”),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE, showline = FALSE, title = “”)
)

l <- l %>% layout(showlegend = FALSE,
title = “Top 5 Trade Countries”,
xaxis = list(tickangle = 0, title = “”),
updatemenus = list(
list(
type = “buttons”,
x= 0.6,
y=1,
buttons = list(
list(method = “restyle”,
args = list(“visible”, list(TRUE, FALSE)),
label = “Export”),

    list(method = "restyle", 
         args = list("visible", list(FALSE, TRUE)), 
         label = "Import")
    
  )
)

)
)

b <- plot_ly(data, x = ~ Countries) %>%
add_bars(y = ~ Trade Balance, name = “Trade Balance”, showlegend = FALSE, color =‘green’)%>%
layout(xaxis = list(title = “Countries”))

s <- subplot(b, l) %>% layout(width = 1000)
s

Help… pleaseeeeeeeeeeeeeeee