Creating a WORDLE app in Shiny:
https://www.youtube.com/watch?v=quvz4xLbW88
The app: https://winston.shinyapps.io/wordle/
Creating a WORDLE app in Shiny:
https://www.youtube.com/watch?v=quvz4xLbW88
The app: https://winston.shinyapps.io/wordle/
Your project: code it progressively & continuously! Ask me questions along the way. Next session is about deployment: it’s better if you have an app to deploy :)
About the next sessions… :
- S5 (today): lots of tips for UI organization - a bit of time at the end for questions
- S6 (next time): light! (styling & deployment) \(\rightarrow\) time to help on projects
- S7: Geocomputing & Twitter example: API & text mining
- S8: chatGPT / modelling (clustering) / stats (regression-tests) / python…?
About the exercises: usually the outcome is pretty ugly. They are intended to make you practice! Up to you to make YOUR project look good!
Idea: post for the best app(s).
Great projects require 2 components: technical skills (coding) + UI/UX acumen.
Commas & brackets! => use Cmd + I (mac) or Ctrl + I (PC) to indent.
Columns: 12 units in what is called the Bootstrap grid system.
In shiny(dashboard), most width are computed on this scale (versus pixels). Sometimes, pixels are available.
Via fluidRow()!
dashboardBody( fluidRow( column(6,valueBoxOutput("box1", width = 12)), column(6,infoBoxOutput("box2", width = 12)) ) )
fluidRow( column(6, checkboxGroupInput("season", h4("Season"), choices = list("Summer" = "Summer", "Winter" = "Winter"), selected = c("Summer", "Winter")) ), column(6, checkboxGroupInput("gender", h4("Gender"), choices = list("Women" = "Women", "Men" = "Men"), selected = c("Women", "Men")) ) )
With the DT (DataTable) package, you can customize the number of rows.
\(\rightarrow\) Test the search feature!
More options:
https://rstudio.github.io/DT/shiny.html
https://rstudio.github.io/DT/options.html
https://rstudio.github.io/DT/010-style.html
output$pt <- DT::renderDataTable({data()}, options = list( lengthMenu = list(c(5, 12, 19), c('5', '12', '19')), pageLength = 5 ))
dashboardBody( tabBox( title = "Results", height = "920px", width = 12, # Width in bootstrap, height in px tabPanel("Countries through time", plotOutput("plot", height = 300), DT::dataTableOutput("pt") ) ) )
Menus show material in the body OR in the sidebar, but not in both!
Resources:
https://rstudio.github.io/shinydashboard/behavior.html
https://rstudio.github.io/shinydashboard/get_started.html
dashboardSidebar( sidebarMenu( menuItem("Plot", tabName = "plot", icon = icon("images", lib = "font-awesome")), menuItem("Table", tabName = "table", icon = icon("table", lib = "font-awesome")) ) ), dashboardBody( tabItems( tabItem(tabName ="plot", plotOutput("plot", height = 300) ), tabItem(tabName ="table", DT::dataTableOutput("pt") ) ) )
Part of the code is located in the Sidebar (layout), and part in the body (content).
The link is the tabName.
menuItem("Display options", numericInput("max_country", h4("Max number countries"), min = 2, max = 12, step = 1, value = 6) )
The code stacks panels with proper names and then displays some object. Below, the objects plot, pt and text are defined in the server.
# Inside the body navlistPanel( "Stuff A", tabPanel("Graph 1", plotOutput("plot")), tabPanel("Table 2", DT::dataTableOutput("pt")), "Header B", tabPanel("Text 3", h1(textOutput("text"))), tabPanel("Component 4"), "-----", tabPanel("Component 5"), widths = c(2,10) )
Navbars are usually used in pure Shiny (not in shinydashboards). They are a bit redundant with sidebars.
infoBox & valueBox!
From server with renderInfoBox() \(\rightarrow\) to UI via infoBoxOutput()
From server with renderValueBox() \(\rightarrow\) to UI via valueBoxOutput()
See also tabBox().
output$box1 <- renderValueBox({ valueBox( value = sum(data()$Medal=="Gold"), subtitle = "Gold", icon = icon("medal", lib = "font-awesome"), color = "yellow" ) })
Be careful, for infoBoxes, there is a title & a subtitle.
Static boxes: https://rstudio.github.io/bslib/articles/value-boxes.html.
For icons: https://fontawesome.com/search.
Sadly, the choice is limited…
See also: https://rinterface.github.io/bs4Dash/reference/infoBox.html https://rinterface.github.io/bs4Dash/reference/valueBox.html
It’s always better to resort to plotly: https://plot.ly/r/ It’s incredibly simple and very effective!
1. In the server: renderPlot() \(\rightarrow\) renderPlotly()
2. In the server, save the ggplot in a variable and then use ggplotly()
3. In the UI (body): plotOutput() \(\rightarrow\) plotlyOutput()
library(plotly) g <- ggplot(diamonds, aes(x = color, fill = color)) + geom_bar() ggplotly(g)
Two options:
img(src = 'https://serverblabla/my_Image.png', width = "50%", height = "50%", align = "center")
img(src ='image_name.png')
Recommended file types: png, jpeg, svg.
Even the best make errors: https://twitter.com/hadleywickham/status/1188516615635324928?s=11
Next time is the last pure Shiny session: make progress if you want me to help you!
Also, I will talk about app online deployment. If you don’t have an app that works, use one from the course.