闪亮应用程序中基于串扰值的子集数据集
Subset dataset based on crosstalk value in a shiny app
我使用串扰是为了能够单击条形图中的条形图并根据 Abcd
对下面的 table 进行子集化。出于某种原因,如果我按下一个条形图,我只会得到一行数据集,而我应该得到所有的数据集。如果我再次 select 所有条, table 仍然只显示一行。
---
title: "Operaitonal dashboard"
author: "Report"
date: 'Date: `r Sys.Date()`'
output:
flexdashboard::flex_dashboard:
orientation: columns
theme: lumen
vertical_layout: scroll
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE,
warning= FALSE,
message = FALSE)
library(crosstalk)
library(shiny)
library(plotly)
library(flexdashboard)
library(ggplot2)
library(dplyr)
library(reactable)
##The four dataframes
Abcd<-c("A","A","B","B")
Prod<-c(34,56,56,89)
Div<-c("Ent","Ent","App","High")
dcross1<-data.frame(Abcd,Prod,Div)
Counts<-c(45,67,78,56)
dcross2<-data.frame(Div,Abcd,Counts)
shared_df <- SharedData$new(dcross1, key = ~Abcd, group = "group")
shared_df2 <- SharedData$new(dcross2, key = ~Abcd, group = "group")
```
# Out of stock Report {data-icon="fa-cart-arrow-down" data-orientation=rows}
## Row {data-height="200"}
### Out Of Stock: Store Overview {data-width="200"}
```{r Oos Store}
daily_store_oos_gg<-
ggplot(shared_df,
aes(x=Abcd,
y=Prod,
fill=as.factor(Abcd)
)) +
geom_bar(stat="identity", position="dodge")
# Convert to plotly object
daily_store_oos_ply <-
ggplotly(daily_store_oos_gg)
daily_store_oos_ply
```
## Column {data-width=405}
### Store Overview Out of Stock
```{r out of stock reactable}
daily_item_oos_rctble<-reactable(
shared_df2
)
daily_item_oos_rctble
```
根据某人的建议,reactable
不能与 crosstalk
一起使用。也许你的数据可以准备如下所示。
试试这个
Abcd<-c("A","A","B","B")
Prod<-c(34,56,56,89)
Div<-c("Ent","Ent","App","High")
dcross1<-data.frame(Abcd,Prod,Div)
Countd<-c(45,67,78,56)
dcross2<-data.frame(Div,Abcd,Countd)
Store<-c(199,199)
Abcd<-c("A","B")
Oos<-c(500,400)
store<-data.frame(Store,Abcd,Oos, flag=1)
Man<-c("Corp","Adv","Corp","Adv")
Abcd<-c("A","B","A","B")
Counts<-c(45,56,34,78)
Scounts<-c(23,45,67,67)
Per<-c(1,2,3,5)
supplier<-data.frame(Abcd,Man,Counts,Scounts,Per) # %>% SharedData$new()
supplier2 <- supplier[order(supplier$Abcd),]
dcross <- cbind(dcross1[,2:3], dcross2[,2:3], supplier2[,2:5]) %>% mutate(id = row_number())
dcross_sub <- group_by(dcross, Abcd) %>% slice(1) %>% select(Abcd, id)
store_sub <- merge(x = dcross_sub, y = store, by = "Abcd", all = TRUE)
dcrossf <- merge(x = dcross, y = store_sub[,2:5], by = "id", all = TRUE)
ui <- fluidPage(
bscols(widths = 6,
list(
plotlyOutput("storep"),
DTOutput("dcross1t")
)
)
)
server <- function(input, output) {
row.names(dcrossf) <- NULL
dcross11 <- SharedData$new(dcrossf, key = ~Abcd, group = "group")
store2 <- SharedData$new(subset(dcrossf, flag==1), key = ~Abcd, group = "group")
daily_store_oos_gg<-
ggplot(store2,
aes(x=Abcd,
y=Oos,
fill=as.factor(Abcd)
)) + labs(fill="Abcd") +
geom_bar(stat="identity", position="dodge")
# Convert to plotly object
daily_store_oos_ply <-
ggplotly(daily_store_oos_gg)
output$storep <- renderPlotly({daily_store_oos_gg })
output$dcross1t <- renderDT({dcross11}, server=FALSE)
}
shinyApp(ui, server)
我使用串扰是为了能够单击条形图中的条形图并根据 Abcd
对下面的 table 进行子集化。出于某种原因,如果我按下一个条形图,我只会得到一行数据集,而我应该得到所有的数据集。如果我再次 select 所有条, table 仍然只显示一行。
---
title: "Operaitonal dashboard"
author: "Report"
date: 'Date: `r Sys.Date()`'
output:
flexdashboard::flex_dashboard:
orientation: columns
theme: lumen
vertical_layout: scroll
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE,
warning= FALSE,
message = FALSE)
library(crosstalk)
library(shiny)
library(plotly)
library(flexdashboard)
library(ggplot2)
library(dplyr)
library(reactable)
##The four dataframes
Abcd<-c("A","A","B","B")
Prod<-c(34,56,56,89)
Div<-c("Ent","Ent","App","High")
dcross1<-data.frame(Abcd,Prod,Div)
Counts<-c(45,67,78,56)
dcross2<-data.frame(Div,Abcd,Counts)
shared_df <- SharedData$new(dcross1, key = ~Abcd, group = "group")
shared_df2 <- SharedData$new(dcross2, key = ~Abcd, group = "group")
```
# Out of stock Report {data-icon="fa-cart-arrow-down" data-orientation=rows}
## Row {data-height="200"}
### Out Of Stock: Store Overview {data-width="200"}
```{r Oos Store}
daily_store_oos_gg<-
ggplot(shared_df,
aes(x=Abcd,
y=Prod,
fill=as.factor(Abcd)
)) +
geom_bar(stat="identity", position="dodge")
# Convert to plotly object
daily_store_oos_ply <-
ggplotly(daily_store_oos_gg)
daily_store_oos_ply
```
## Column {data-width=405}
### Store Overview Out of Stock
```{r out of stock reactable}
daily_item_oos_rctble<-reactable(
shared_df2
)
daily_item_oos_rctble
```
根据某人的建议,reactable
不能与 crosstalk
一起使用。也许你的数据可以准备如下所示。
试试这个
Abcd<-c("A","A","B","B")
Prod<-c(34,56,56,89)
Div<-c("Ent","Ent","App","High")
dcross1<-data.frame(Abcd,Prod,Div)
Countd<-c(45,67,78,56)
dcross2<-data.frame(Div,Abcd,Countd)
Store<-c(199,199)
Abcd<-c("A","B")
Oos<-c(500,400)
store<-data.frame(Store,Abcd,Oos, flag=1)
Man<-c("Corp","Adv","Corp","Adv")
Abcd<-c("A","B","A","B")
Counts<-c(45,56,34,78)
Scounts<-c(23,45,67,67)
Per<-c(1,2,3,5)
supplier<-data.frame(Abcd,Man,Counts,Scounts,Per) # %>% SharedData$new()
supplier2 <- supplier[order(supplier$Abcd),]
dcross <- cbind(dcross1[,2:3], dcross2[,2:3], supplier2[,2:5]) %>% mutate(id = row_number())
dcross_sub <- group_by(dcross, Abcd) %>% slice(1) %>% select(Abcd, id)
store_sub <- merge(x = dcross_sub, y = store, by = "Abcd", all = TRUE)
dcrossf <- merge(x = dcross, y = store_sub[,2:5], by = "id", all = TRUE)
ui <- fluidPage(
bscols(widths = 6,
list(
plotlyOutput("storep"),
DTOutput("dcross1t")
)
)
)
server <- function(input, output) {
row.names(dcrossf) <- NULL
dcross11 <- SharedData$new(dcrossf, key = ~Abcd, group = "group")
store2 <- SharedData$new(subset(dcrossf, flag==1), key = ~Abcd, group = "group")
daily_store_oos_gg<-
ggplot(store2,
aes(x=Abcd,
y=Oos,
fill=as.factor(Abcd)
)) + labs(fill="Abcd") +
geom_bar(stat="identity", position="dodge")
# Convert to plotly object
daily_store_oos_ply <-
ggplotly(daily_store_oos_gg)
output$storep <- renderPlotly({daily_store_oos_gg })
output$dcross1t <- renderDT({dcross11}, server=FALSE)
}
shinyApp(ui, server)