Garrick Aden-Buie преди 6 години
родител
ревизия
739d594501
променени са 2 файла, в които са добавени 64 реда и са изтрити 0 реда
  1. +25
    -0
      dev/dev.Rmd
  2. +39
    -0
      dev/shiny/app.R

+ 25
- 0
dev/dev.Rmd Целия файл

@@ -455,3 +455,28 @@ tooltipOptions = list(
formatTooltipY = htmlwidgets::JS("d => d + ' babies'")
)
```

## Shiny comes for free!

Create a basic Shiny app with

1. Slider input to pick number of values (1:26 letters)
1. A new data button that generates new data of same dimension
1. The data are reactive, `x = letters[1:n]`, `y = runif(n)`
1. Use `frappeCharts::frappeChartOutput()` linked to `frappeCharts::renderFrappeChart()`
- bar plot
- fix `tooltipOptions` to turn the `runif()` into a percent.
`dev/shiny/app.R`

Make a mistake in the spelling for `formatTooltipY`
and demo how hard it is for the end user to track down what's wrong.
This points to how important it is to do the validation on the R side
or to do the extra work to make the R API friendly.

It's also a good place to demo debug strategies for Shiny and regular widgets.
Open the app in an external window,
show the dev console,
find the frappeCharts binding
and add a breakpoint.
Then reload and show how you an use the dev console there to figure things out.

+ 39
- 0
dev/shiny/app.R Целия файл

@@ -0,0 +1,39 @@
library(shiny)

ui <- fluidPage(
# Application title
titlePanel("htlmwidgets rock"),
sidebarLayout(
sidebarPanel(
# Sidebar with a button to create new data
sliderInput("n_bars", "Number of bars", 1, 26, 10),
actionButton("new_data", "New Data")
),
# Show a plot of the generated distribution
mainPanel(
frappeCharts::frappeChartOutput("chart")
)
)
)

# Define server logic required to draw a histogram
server <- function(input, output) {
data <- reactive({
input$new_data

data.frame(x = LETTERS[seq_len(input$n_bars)], Frequency = runif(input$n_bars))
})

output$chart <- frappeCharts::renderFrappeChart({
frappeCharts::frappeChart(
data(),
type = "bar",
tooltipOptions = list(
formatTooltipY = htmlwidgets::JS("d => Math.round(d * 100) + '%'")
)
)
})
}

# Run the application
shinyApp(ui = ui, server = server)

Loading…
Отказ
Запис