Hi all,
I have tried with below code to make sure the columns are very reactive. But for some reason, the filter I get here are empty and nothing is filled . I know there is some issue here.
Basically what i am looking for is,
the columns filter should be reactive based on the selection.
For example "Rat" filter should be reactive based in selection in "New" filter and vice versa. Can anyone help me?
library(shiny)
library(readxl)
library(dplyr)
library(shinyWidgets) ## for picker input
library(shinydashboard)
library(DT)
library(tidyverse)
library(xtable)
library(shinycssloaders)
library(plotly)
library(htmlwidgets)
library(sparkline)
library(data.table)
require(reshape2)
library(glue)
data_13_Sam <- data.frame(
Ratings = c(1,2,3,4,5,1,2,3,4,5), flag = c("Yes","No","Yes","No","Yes","No","Yes","No","Yes","No")
)
ui <- fluidPage(
column(offset = 0, width = 1,uiOutput("rat")),
column(offset = 0, width = 2, uiOutput("nt"),
actionButton("abid","ab"))
)
server <- function(input, output, session) {
filter_data <- reactive({
data_13_Sam %>% filter(flag %in% input$nt, Ratings %in% input$rat)
})
filter_data_rat <- reactive({
data_13_Sam %>% filter(flag %in% input$nt)
})
filter_data_nt <- reactive({
data_13_Sam %>% filter(Ratings %in% input$rat)
})
##### nt
ntopic <- reactiveVal(unique(data_13_Sam$flag))
observeEvent(input$abid,{
ntopic(c("No","Yes"))
})
observe({
asd_nt <- as.data.frame(filter_data_nt() %>% group_by(flag) %>% summarise(Reviews = n())) %>% mutate(Det = paste0(flag, ":", Reviews))
output$nt <- renderUI({
pickerInput("nt",label = tags$h4("New"),choices = c(deframe(asd_nt[3:1])) , multiple = TRUE,selected = ntopic(),
options = list(
`actions-box` = TRUE,
`deselect-all-text` = "None",
`select-all-text` = "Select All"
))
})
})
observeEvent(input$nt,
ntopic(input$nt))
###### rat
rtg <- reactiveVal(unique(data_13_Sam$Ratings))
observeEvent(input$abid,{
rtg(unique(data_13_Sam$Ratings))
})
observe({
asd_ra <- filter_data_rat() %>% group_by(Ratings) %>% summarise(Reviews = n()) %>% mutate(Det = paste0(Ratings, ":", Reviews))
output$rat <- renderUI({
pickerInput("rat",label = tags$h4("Rat"),choices = c(setNames(seq_along(asd_ra$Ratings), asd_ra$Det)) , multiple = TRUE,selected = rtg(),
options = list(
`actions-box` = TRUE,
`deselect-all-text` = "None",
`select-all-text` = "Select All"
))
})
})
observeEvent(input$rat,
rtg(input$rat))
}
shinyApp(ui, server)