mine.tables

Author
Published

June 12, 2024

A. Purpose of this submission

  1. Enjoyable table

I was thinking about what table to create for the table contest 2024, I wanted to create a use case for a table that could be enjoyed without context or understanding of the data. So, although I am not a professional game developer, I created a “Minesweeper” game using tables.

  1. Various table

I wanted to showcase the capabilities of different tables.

There are a lot of packages available for working with tables in R, each with their own strengths and weaknesses. I haven’t used all of them, but I didn’t want to limit myself to just one package.

I used reactable, which is my favourite, DT, which was the first one I started using, and finally gt, which has recently been getting a lot of love in the clinical domain.

Of course, there are other valuable packages like flextable and data.table, but I don’t have time to cover them all.

  1. Interactive table

Since I’m using shiny, I wanted to create some interaction with the user or external services in the table, so I threw in a little bit of LLM functionality, which is all the rage these days.

B. How to play mine-sweeper

This can be followed as Guide with Cicerone in Shiny application

C. How to use Gemini

  • get API key from Google AI Studio (FREE!)
  • this feature uses R package {gemini.R} see link

D. Code explanation

Part 1. Libaries

I used 11 R packages in this mine.tables

library(reactable)
library(DT)
library(gt)

library(shiny)
library(shinyWidgets)
library(bslib)
library(bsicons)
library(shinyjs)
library(cicerone)

library(magrittr)
library(gemini.R)

First 3 is for table work, and next 6 is for shiny application, and last 2 is for API call gemini.

Part 2. Shiny UI

Since you may see Every code, I attached image of key functions

Part 3. Shiny Server

Server logic is consisted with 5 major parts.

  1. mine sweeper game
  • Randomly generate data with given size and mine (START)
  • Get click input from user
  • Check if it is mine or not and show results
  1. reactable
  • To get clicked cell from user with reactable, I used onClick parameter of reactable to create “Shiny.setInputValue” (Javascript Event
  • render mine count, and mine emoji with color_text function which return HTML element with color.
  1. DT
  • To implement Button-like table with DT. used escape parameter to use HTML tag.
  • In cell element (Button) it uses onclick to open github repository.
  • The pagination doesn’t affect functionality, but I left it on purpose because without it, it’s hard to tell it’s a table.
  1. gt
  • Also, to implement Button-like table with gt, I used HTML in tab_header to button. (Which has onclick for this document)
  • However, gt seems must show body so I used column to button and body to just show empty.
  1. gemini and cicerone
  • See their own repo please.

E. Summary

I made little game-like shiny application with various table R package, and I hope you enjoy it.