问题描述
我想创建一个钻取图表。基于 https://plotly-r.com/linking-views-with-shiny.html#drill-down 链接,我为特定变量创建了下钻,但现在我必须根据下拉值构建下钻。如何创建?
data:
col1 col2 sales
A E 20
B G 10
B H 15
A H 5
ui.R:
fluidRow(
column(width=4,selectInput("colid","Select",choices = c("col1"))),),plotlyOutput('drilldown1',height = 500),plotlyOutput("drilldown2",height = 500)
server.R :
if(input$colid==as.character("col1")){
drilldown1 <- reactiveVal()
drilldown2 <- reactiveVal()
observeEvent(event_data("plotly_click",source = "drilldown1"),{
drilldown1(event_data("plotly_click",source = "drilldown1")$x)
drilldown2(NULL)})
observeEvent(event_data("plotly_click",source = "drilldown2"),{
drilldown2(
event_data("plotly_click",source = "drilldown2")$x
)})
output$drilldown1<- renderPlotly({
df <- data %>%
dplyr::group_by(col1) %>%
dplyr::summarise('Mean'=round(mean(sales,na.rm=TRUE),digits =0))
)
fig1 <-plot_ly(x = ~df$col1,y = ~df$Mean,type='bar',source =
"drilldown1")
fig1
})
output$drilldown2<- renderPlotly({
if (is.null(drilldown1())) return(NULL)
df <- data %>%
dplyr::filter(col1 %in% drilldown1()) %>%
dplyr::group_by(col2) %>%
dplyr::summarise('Mean'=round(mean(sales,digits = 0))
)
fig2 <-plot_ly(x = ~df$col2,source =
"drilldown2")
fig2
})
}
I am getting below error:
Error in : Can't access reactive value 'colid' outside of reactive consumer.
请帮帮我。我已经搜索过这个我无法得到明确的答案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)