Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode: LEARN MORE

Shiny app filtering not working

Solved!
Nilafhiosagam
Level 2
Shiny app filtering not working

Hi all. New to Dataiku and shiny but facing an issue where my app is not being populated with column names as you can see in the attached screenshot. The app without any filtering applied that just prints the head of the data works. The log is fine 

Loading required package: shiny
Listening on http://127.0.0.1:6288

 

UI:

 

 

library(shiny)


# Define UI
ui <- fluidPage(
  titlePanel("Display Top 10 Rows of Dataset"),
  sidebarLayout(
    sidebarPanel(
      selectInput("column", "Select Column:", choices = colnames(df)),
      textInput("filter", "Filter Value:")
    ),
    mainPanel(
      tableOutput("topRows")
    )
  )
)

 

 

Server:

 

library(shiny)
library(dataiku)

# Function to read dataset 
df <- dkuReadDataset("final_data")

server <- function(input, output) {
  # Reactive expression to filter dataset
  filteredData <- reactive({
    req(input$column, input$filter)
    df[df[[input$column]] == input$filter, ]
  })
  
  # Display the top 10 rows
  output$topRows <- renderTable({
    head(filteredData(), 10)
  })
}

 

 

0 Kudos
1 Solution
Nilafhiosagam
Level 2
Author

OK I've now realised that I need to read the data in both the ui and server via

df <- dkuReadDataset("final_data")

 

View solution in original post

0 Kudos
2 Replies
Nilafhiosagam
Level 2
Author

To add, specifying the column name gives me "An error has occurred!
object of type 'closure' is not subsettable" with code as follows:

 

UI

 

library(shiny)


# Define UI
ui <- fluidPage(
  titlePanel("Filter Dataframe by Article"),
  
  sidebarLayout(
    sidebarPanel(
      selectInput("article", "Select Article:", choices = unique(df$ARTICLE))
    ),
    
    mainPanel(
      tableOutput("table")
    )
  )
)

 

 

Server:

 

library(shiny)
library(dataiku)

# Function to read dataset 
df <- dkuReadDataset("final_data")

# Define server logic for the application
server <- function(input, output) {
  filtered_df <- reactive({
    df[df$ARTICLE == input$article, ]
  })
  
  output$table <- renderTable({
    head(filtered_df())
  })
}

 

 

Attached is me just rendering the table with the ARTICLE column visible

 

 

0 Kudos
Nilafhiosagam
Level 2
Author

OK I've now realised that I need to read the data in both the ui and server via

df <- dkuReadDataset("final_data")

 

0 Kudos