Code Monkey home page Code Monkey logo

r-shinylive-demo's People

Contributors

coatless 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

Watchers

 avatar  avatar  avatar

r-shinylive-demo's Issues

Problem converting an existing example app to Quarto standalone

I can run the below example Shiny app as an app.R (which pulls in some external data) without any problems, but get "page not found" (404) when attempting to Render within a Quarto document as a standalone app.

Within the same Quarto document, I have the demo (histogram) example as a second standalone app in a separate {shinylive-r} chunk and this is rendering correctly, so the Quarto set-up (extension, filter etc.) is working fine.

Any thoughts?

```{shinylive-r}
#| standalone: true
#| viewerHeight: 600
library(shiny)
library(gridlayout)
library(rvest)
library(tidyverse)
library(scales)
library(pageviews)
library(lubridate)
library(bslib)
library(wesanderson)

charts <-
  tibble(
    chart = read_html(str_c(
      "https://en.wikipedia.org/wiki/",
      "Category:Statistical_charts_and_diagrams"
    )) |>
      html_elements(".mw-category-group a") |>
      html_text()
  )

pv <- function(article) {
  article_pageviews(
    project = "en.wikipedia",
    article,
    user_type = "user",
    start = "2015070100",
    end = today()
  )
}

theme_set(theme_bw())

cols <- wes_palette(8, name = "IsleofDogs1", type = "continuous")

ui <- grid_page(
  theme = bs_theme(version = 5, 
                   bootswatch = "simplex",
                   primary = "#9986A5"),
  layout = c(
    "header  header",
    "sidebar line "
  ),
  row_sizes = c(
    "100px",
    "1fr"
  ),
  col_sizes = c(
    "250px",
    "1fr"
  ),
  gap_size = "1rem",
  grid_card(
    area = "sidebar",
    item_alignment = "top",
    title = "Options",
    item_gap = "13px",
    dateRangeInput("dates",
      label = "Date range",
      start = "2015-07-01",
      end = NULL
    ),
    selectizeInput(
      inputId = "article",
      label = "Chart type",
      choices = charts,
      selected = c(
        "Violin plot",
        "Dendrogram",
        "Histogram",
        "Pie chart",
        "Q–Q plot",
        "Error bar"
      ),
      options = list(maxItems = 8),
      multiple = TRUE
    ),
    selectInput(
      inputId = "scales",
      label = "Fixed or free y-axis",
      choices = c("Fixed" = "fixed", "Free" = "free"),
      selected = "fixed"
    ),
    selectInput(
      inputId = "log10",
      label = "Log 10 or normal y-axis",
      choices = c("Log 10" = "log10", "Normal" = "norm"),
      selected = "log10"
    )
  ),
  grid_card_text(
    area = "header",
    content = "   Plot Plotter   ",
    alignment = "center",
    is_title = FALSE
  ),
  grid_card_plot(area = "line")
)

server <- function(input, output, session) {
  subsetr <- reactive({
    req(input$article)
    pageviews <- map_dfr(input$article, pv) |>
      mutate(
        date = ymd(date),
        article = str_replace_all(article, "_", " ")
      ) |>
      filter(date >= input$dates[1], date <= input$dates[2])
  })

  output$line <- renderPlot({
    p <- ggplot(
      subsetr(),
      aes(date,
        views,
        colour = article
      )
    ) +
      geom_line() +
      scale_colour_manual(values = cols) +
      geom_smooth(colour = cols[7]) +
      facet_wrap(~article, nrow = 1, scales = input$scales) +
      theme(
        legend.position = "none",
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.margin = margin(1, 1, 1, 1, "cm")
      ) +
      labs(
        x = NULL, y = NULL,
        caption = "\nSource: Daily Wikipedia Article Page Views"
      )

    switch(input$log10,
      norm = p,
      log10 = p + scale_y_log10(labels = label_number(scale_cut = cut_short_scale()))
    )
  })
}

shinyApp(ui, server)
```

How to show the app code along with the app in shinylive?

Thank you for providing this demo. Really useful!

I was wondering if it is possible to show the code alongside the app? Similar to the display.mode = "showcase" option in runApp()? I tried it in the shinylive-r chunk but the app did not render.

shinylive asset directory error on Windows

Hi James, what a nice work that you are doing here! I tried to run the example (following the instructions here and from youtube) but cound´t make it work!
The error log is as following:

Error running Rscript (error code 1): <no output>
`C:/Users/arthur/AppData/Local/shinylive/shinylive/Cache/shinylive-0.2.0` assets directory does not exist.

Using shinylive::assets_ensure(), it tried to fix the error:

`C:/Users/arthur/AppData/Local/shinylive/shinylive/Cache/shinylive-0.2.0` assets directory does not exist.
Downloading shinylive v0.2.0...
trying URL 'https://github.com/posit-dev/shinylive/releases/download/v0.2.0/shinylive-0.2.0.tar.gz'
Content type 'application/octet-stream' length 254533686 bytes (242.7 MB)
downloaded 147.5 MB

Warning: downloaded length 154707153 != reported length 254533686Warning: URL 'https://objects.githubusercontent.com/github-production-release-asset-2e65be/487125727/7829914b-cc7b-4f3c-8b2d-7ee3cb9c8f70?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230922%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230922T173955Z&X-Amz-Expires=300&X-Amz-Signature=a9f86f6726d92c9866607225bcc454843faefa46bce022ac85b5061375f9d86f&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=487125727&response-content-disposition=attachment%3B%20filename%3Dshinylive-0.2.0.tar.gz&response-content-type=application%2Foctet-stream': Timeout of 60 seconds was reachedError in utils::download.file(url, destfile = tmp_targz, method = "auto") : 
  download from 'https://github.com/posit-dev/shinylive/releases/download/v0.2.0/shinylive-0.2.0.tar.gz' failed

any thoughts?

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.