Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

54 lines
1.2KB

  1. library(shiny)
  2. ui <- fluidPage(
  3. # Application title
  4. titlePanel("htlmwidgets rock"),
  5. sidebarLayout(
  6. sidebarPanel(
  7. # Sidebar with a button to create new data
  8. sliderInput("n_bars", "Number of bars", 1, 26, 10),
  9. actionButton("new_data", "New Data")
  10. ),
  11. # Show a plot of the generated distribution
  12. mainPanel(
  13. frappeCharts::frappeChartOutput("chart"),
  14. verbatimTextOutput("selected")
  15. )
  16. )
  17. )
  18. # Define server logic required to draw a histogram
  19. server <- function(input, output, session) {
  20. initial_data <- data.frame(
  21. x = LETTERS[seq_len(10)],
  22. Frequency = rep(0.5, 10)
  23. )
  24. data <- reactive({
  25. input$new_data
  26. data.frame(x = LETTERS[seq_len(input$n_bars)], Frequency = runif(input$n_bars))
  27. })
  28. output$chart <- frappeCharts::renderFrappeChart({
  29. frappeCharts::frappeChart(
  30. initial_data,
  31. type = "bar",
  32. tooltipOptions = list(
  33. formatTooltipY = htmlwidgets::JS("d => Math.round(d * 100) + '%'")
  34. )
  35. )
  36. })
  37. observe({
  38. updateFrappeChart("chart", data())
  39. })
  40. output$selected <- renderPrint({
  41. input$chart_selected
  42. })
  43. }
  44. # Run the application
  45. shinyApp(ui = ui, server = server)