Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

49 lines
1.1KB

  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. )
  15. )
  16. )
  17. # Define server logic required to draw a histogram
  18. server <- function(input, output, session) {
  19. initial_data <- data.frame(
  20. x = LETTERS[seq_len(10)],
  21. Frequency = rep(0.5, 10)
  22. )
  23. data <- reactive({
  24. input$new_data
  25. data.frame(x = LETTERS[seq_len(input$n_bars)], Frequency = runif(input$n_bars))
  26. })
  27. output$chart <- frappeCharts::renderFrappeChart({
  28. frappeCharts::frappeChart(
  29. initial_data,
  30. type = "bar",
  31. tooltipOptions = list(
  32. formatTooltipY = htmlwidgets::JS("d => Math.round(d * 100) + '%'")
  33. )
  34. )
  35. })
  36. observe({
  37. session$sendCustomMessage("frappeCharts:update", list(id = "chart", data = data()))
  38. })
  39. }
  40. # Run the application
  41. shinyApp(ui = ui, server = server)