12 How to learn Shiny
It’s cool if we can make shiny apps, and sometimes we are asked to make a shiny app at work. So, we do want and need to learn the Shiny package. The question is: How can we quickly learn it? I don’t think there is the best answer to this question, because we all have different learning styles and “one man’s meat is [possibly] another man’s poison.” Here, based on my learning experience, just tell you how I learned the Shiny stuff; it’s only for your reference.
I watched the three webinars presented by Garrett Grolemund a few times; the links are: https://www.rstudio.com/resources/webinars/how-to-start-with-shiny-part-1/ https://www.rstudio.com/resources/webinars/how-to-start-with-shiny-part-2/ https://www.rstudio.com/resources/webinars/how-to-start-with-shiny-part-3/
I watched Winston Chang’s webinar (https://www.rstudio.com/resources/webinars/dynamic-dashboards-with-shiny/) a couple of times.
Practice, using this template
library(shiny)
ui <- fluidPage(
xxxxInput(),
xxxxOutput()
)
server <- function(input, output)
{
R code
}
shinyApp(ui = ui, server = server)
for example,
library(shiny)
ui <- fluidPage(
titlePanel(title = "Shiny Exercise"),
sidebarPanel(width = 4,
sliderInput("RandNum", label = "choose a number",
value = 20, min = 10, max = 100)
),
mainPanel(wideth = 8, plotOutput("scatter"))
)
server <- function(input, output)
{output$scatter <- renderPlot({
x <- rnorm(input$RandNum)
y <- rnorm(input$RandNum)
plot(x, y, xlab = "x", ylab = "y", main = "Scatter plot")
})
}
shinyApp(ui = ui, server = server)
Below is a screenshot
- I made several small apps and published them on https://www.shinyapps.io/ e.g. see these three: https://larryzhang.shinyapps.io/histogramorboxplot/, https://larryzhang.shinyapps.io/distributions/, and https://larryzhang.shinyapps.io/city_map/