Git Product home page Git Product logo

mastering-shiny's Introduction

Build Status

This is the work-in-progress repo for the book Mastering Shiny by Hadley Wickham. It is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Built with bookdown.

Images

There are three directories for images:

  • diagrams/ contains omnigraffle diagrams. Source of truth is .graffle files. Can delete all subdirectories.

  • screenshots/ contains programmatic screenshots. Source of truth is book code. Can delete all subdirectories.

  • images/ contains images created some other way. Images are source of truth and should not be deleted.

mastering-shiny's People

Contributors

bscowboy avatar chsafouane avatar daattali avatar danieldavid521 avatar edovt avatar emilopezcano avatar esimms999 avatar federicomarini avatar hadley avatar hedsnz avatar hlynurhallgrims avatar hsm207 avatar jcheng5 avatar jonmcalder avatar malcolmbarrett avatar mattwarkentin avatar maurolepore avatar michael-dewar avatar mine-cetinkaya-rundel avatar mitsuoxv avatar mpaulacaldas avatar psychometrician avatar scottyd22 avatar sedaghatfar avatar shmuhammadd avatar sowla avatar stevensbr avatar tmstauss avatar trekonom avatar valerivoev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mastering-shiny's Issues

Connecting progress conditions to shiny

shinyProgress <- function(expr) {
  progress <- NULL
  on.exit(if (!is.null(progress)) progress$close())
  
  tryCatch(expr,
    progress_message = function(cnd) {
      switch(cnd$msgtype,
        add_job = {
          progress <<- Progress$new()
        },
        complete_job = {
          progress$close()
          progress <<- NULL
        },
        set_job_status = progress$set(message = cnd$status),
        set_job_output = progress$set(details = cnd$output),
        set_job_progress = progress$set(value = cnd$progress),
        add_job_progress = progress$inc(amount = cnd$increment)
      )
    }
  )
}

long_process <- functon() {
  pb <- progress_bar$new(total = 100)
  for (i in 1:100) {
    pb$tick()
    Sys.sleep(1 / 100)
  }
  100
}

And with vroom since it already uses progress.

What is a side-effect?

https://github.com/jcheng5/shiny-book/blob/6116549ee9181d761d210a624590d5dde38fcaf4/07-demystifying-reactivity.Rmd#L220

Though outputs allow (and may even require) side effects, this doesn’t mean you should include just any side effects in your output code.

In the previous paragraph, you mention that renderPrint() expects calls to print() , and renderPlot() (may) expect you to draw a plot, but you don't explicitly mention these are side-effects. I think it would be good to be a little more explicit about that (i.e., don't leave your readers wondering: what is a side-effect? when and why do outputs require them?)

It might also be worthwhile demonstrating or explaining why you should avoid side-effects in your output code (and maybe even in general), even if you just point to another section or appendix

max-increase figure in action-dynamic.Rmd

demo$screenshot("max-increase") is showing the max at 3, not 4. I haven't dug through how things work enough to find where that figure actually "lives" to make sure it hasn't already been updated, though.

Show how to create UI with code

Without using dynamic UI — e.g. imagine you have a bunch of sliders who's min, max, and starting value change every 3 months, and are recorded in a csv file (i.e. they're supplied by the business stakeholders and you want to make them as easy to update as possible). Show how to use a little functional programming to create en masse.

Introduce CRAN example app before walking through implementation

In these sort of scenarios I find it helpful to work backwards: first show the completed app (maybe link to a gif or video demoing the interactive behavior). Then you could even make some exercises for the reader before walking through the details, could ask:

(1) What are the reactive values in this app? Asking this question first and partially addressing it right away can help explain why your script has these "configuration variables"
(2) What are the outputs?
(3) Can you predict how reactive expressions might be useful for this app?

Then you could introduce the data and walk through the steps

Explain disadvantages of global.R

Re: action-modules.Rmd, line 15: It would be valuable to explain in more detail why global.R is not the preferred place to put globally-accessible code.

As of October 2019, several pages extolling the virtues of global.R appear high on a Google search for shiny global.R. This would be a good place to present arguments against global.R.

could not find function "consoleReactive"

Hi Hadley,

First, thanks for this awesome book, I learned a gazillion things!

In chapters 7 and 10, you use the consoleReactive(TRUE) statement, but I could not find this function anywhere, even in shiny github repo or in google search.

From where am I supposed to import it?

github actions build

Hey @jimhester & @hadley.

I think I know why it doesn't deploy to Netlify in the recent commits.

I was trying to get this set up for our bookdown site the other day https://github.com/EmilHvitfeldt/tidy-nlp-in-R-book and I found that I needed to also run netlify link ...

https://github.com/EmilHvitfeldt/tidy-nlp-in-R-book/blob/2d9ef328f4c7a52a0e6383aaef120a5ace26be30/.github/workflows/bookdown.yaml#L45-L52

Could that be what you needed?

I also wrote a post detailing the process with a sample repository https://github.com/EmilHvitfeldt/bookdown-github-actions-netlify

Typo in 7.2

Thanks for this great book!

I spotted the following minor typo in section 7.2:

"Expressions and outputs should update whenever one of there input values changes. This ensures that input and output stay in sync."

* Expressions and outputs should update whenever one of there input values

Cheers,
-Lucas

Execute code in a reactive environment

What's the easiest way to execute code in a throw away reactive environment? i.e. how could you run this code in order to product an error:

# Don't do this!
  dataset <- get(input$dataset, "package:datasets", inherits = FALSE)

  output$summary <- renderPrint({
    summary(dataset)
  })
  
  output$table <- renderTable({
    dataset
  })

Chapter 2 excerise 5 solution

I can't seem to get this solution to work, I have found the 2 of the 3 supposed bugs, but I was wondering if maybe there is another error in the code before it is published, I have been working on it for atleast a week, here is my github if you can help with a solution. Thank you https://github.com/Danieldavid521/Mastering_Shiny_solutions/blob/master/Mastering_Shiny_Chapter_2-5_solutions.R

Case study chapter for advanced-ui

Similar to the first case study (Getting Started section), I would see a slot for a case study in the advanced-ui part. There are a lot of features mentioned in Chapter 12 that would require a practical example to fit with business needs, that is creating a new template From scratch for instance. I can help in the process.

Explain where the `consoleReactive()` function comes from

It would be nice if you can explain where the consoleReactive() function comes. In the book, I see that the function is mentioned in reactivity-related sections, but it's usually placed after library(shiny) statement. I find this confusing because that function is not one of the exported functions in Shiny. And there's no reference to the common.R file where is the place of this function.

https://github.com/hadley/mastering-shiny/search?q=consoleReactive&unscoped_q=consoleReactive

Or do you have plans to move that function to the Shiny soon?

typo section 2.5

i thought this text was wrong but it is not:

Because both of the rendering code blocks I wrote used input$dataset, 

Suggestion: shinycssloaders package for user feedback chapter 7

Hi,

A small suggestion of a package that I often use to provide user feedback in a shiny app.

https://github.com/andrewsali/shinycssloaders

It provides a very simple function to add a spinner to a plot or table

   withSpinner(plotOutput("my_plot")) 

This compliments the wonderful Waiter/Waitress package that is already mentioned as it is added via the ui rather than the server function.

The use of spinners has provided the best UX improvement in Shiny apps that I have built.

Cheers,

Iain

Capitalization of Shiny

It's shiny when it's the package, but Shiny when it's a "Shiny app".

This issue is to remember to do a search for " shiny" and where appropriate replace it with " Shiny" periodically / before writing is done.

ID or Id?

The text uses "ID", but argument names seem to have Id. I'd suggest "Id" for consistency.

2.7 Exercises

All exercises are labeled as "1". Makes it difficult to follow.

image

3.4.5 assist the reader by expanding on the example

The original code doesn't 'do' anything meaningful.

Consider expanding the code a little, like this (added server and shinyApp at bottom of function) to make the function 'theme_demo' work across the example themes:

theme_demo  <- function(theme) {
  ui <- fluidPage(
    theme = shinythemes::shinytheme(theme),
    sidebarLayout(
      sidebarPanel(
        textInput("txt", "Text input:", "text here"),
        sliderInput("slider", "Slider input:", 1, 100, 30)
      ),
      mainPanel(
        h1("Header 1"),
        h2("Header 2"),
        p("Some text")
      )
    )
  )
  server <- function(input, output) {}
  shinyApp(ui = ui, server = server)
}



theme_demo("darkly")
theme_demo("flatly")
theme_demo("sandstone")
theme_demo("united")

Or turn it into an exercise...

Suggestions on examples

I've been writing Shiny apps in recent 2 years and learned a lot from scattered places. It will be great to have one book to include all the key ideas.

In my learning experience, I think some good examples can really help readers to understand the concept and apply to their own problems. I also would like to share some of tricks I think are very useful.

My first suggestion of example is based on my two answers in Stackoverflow -
Add weblink to actionButton, basically I used actionButton css class for a link, so a link will look like a button. Further more we can make a material button for a link. The key take away in this example is to print the tag function output, explore and set attributes properly.

In customizing css part, it's also worth mentioning the development tools within rstudio or chrome which can work on shiny app directly(you probably have this in mind already).

In reactivity part:

  • turning on options(shiny.trace = TRUE) is often very helpful(I found the reactive log is often overwhelming and less useful).
  • data.table modify variable by reference, so if user was using a data.table for reactive value, they need to set it to NULL then update value again to trigger reactive changes.
  • req is very useful to prevent unwanted error messages or behaviors. However req cannot be used inside data.table bracket like dt[req(var), .N], probably because when req returned Error it was not handled properly inside data.table. req has to be used outside of data.table call.
  • if the execution order of multiple reactive parts is not working as expected,freezeReactiveValue can be helpful (I found different priority settings never worked for me), but often there is a better design by choosing different reactive variables.

I also have to go through lots of trial and errors in using DT row selection to trigger app behavior, because the row selection event was the slowest in shiny app, which often create problem of updates order in reactive context. I can help to provide some example on this but not sure if there is a need for this kind of usage.

Can't access dataset for Ch. 5 case study?

Hi,

I'm trying to work through the Chapter 5 case study, but I can't seem to access the neiss/injuries.tsv.gv referenced.

Specifically, running

injuries <- vroom::vroom("neiss/injuries.tsv.gz")

in the console returns evaluation errors about the file not existing. Did I miss a step about how the data is supposed to be downloaded/set-up for this case study?

Apologies if I'm missing something obvious.

Idea: Tidy evaluation and shiny

I hope you don't mind having user feedback at this early stage 😄

I think there should be a section devoted to how a developer can take advantage of tidy evaluation. Ever since your keynote at R/Pharma 2018 with the demo of the possibilities, it was a real 👀 opener and I could see that being relevant to not just pharma use cases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.