Shiny app filtering not working

Options
Nilafhiosagam
Nilafhiosagam Registered Posts: 7
edited July 16 in Using Dataiku

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)
  })
}

Best Answer

Answers

  • Nilafhiosagam
    Nilafhiosagam Registered Posts: 7
    edited July 17
    Options

    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

Setup Info
    Tags
      Help me…