AntoineSoetewey / statsandr

A blog on statistics and R aiming at helping academics and professionals working with data to grasp important concepts in statistics and to apply them in R. See www.statsandr.com
http://statsandr.com/
35 stars 15 forks source link

blog/how-to-publish-shiny-app-example-with-shinyapps-io/ #49

Closed utterances-bot closed 3 years ago

utterances-bot commented 3 years ago

How to publish a Shiny app: example with shinyapps.io - Stats and R

See a step-by-step guide (with screenshots) on how to deploy and publish online a Shiny app using shinyapps.io

https://statsandr.com/blog/how-to-publish-shiny-app-example-with-shinyapps-io/

kuibaoli commented 3 years ago

I have succeeded in step 16 and edited the app (i.e., replace the entire code by my app).Then I run the app again by clicking on the Run App button. The Shiny app appeared in my computer. I tried to published it in my internet browser by clicking on the Publish button. However.it does not work. It shows as follows. An error has occurred.The application failed to start: exited unexpectedly with code 1. I wonder what the reasons for it. Thanks inadvance.

AntoineSoetewey commented 3 years ago

I have succeeded in step 16 and edited the app (i.e., replace the entire code by my app).Then I run the app again by clicking on the Run App button. The Shiny app appeared in my computer. I tried to published it in my internet browser by clicking on the Publish button. However.it does not work. It shows as follows. An error has occurred.The application failed to start: exited unexpectedly with code 1. I wonder what the reasons for it. Thanks inadvance.

Can you give me the shinyapps.io link to your app? Is the code of your app available on GitHub? If yes, what is the repo? So I can try to publish it on my side to check everything is working smoothly.

Regards, Antoine

saeedraeisi commented 3 years ago

Hello,

I want to publishing a data on shinaapp, i faced with the below error on R, "Error in func(fname, ...) : app.R did not return a shiny.appobj object" And in the shinyapp i faced with "Error in value[3L] : could not find function "%>%" Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted"

This is my code:

df1 <- cases2020 %>% filter(cases<500)

library(tidyverse) library(shiny) library(ggplot2)

Define UI for application that draws a histogram

ui <- fluidPage(

Application title

titlePanel("Old Faithful Geyser Data"),

sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30) ),

mainPanel(
  plotOutput("distPlot") ,
  plotOutput ("fylke")
)

) )

server <- function(input, output) {

output$distPlot <- renderPlot({

Cases_Frequently    <-df1$cases
bins <- seq(min(Cases_Frequently), max(Cases_Frequently), length.out = input$bins + 1)

hist(Cases_Frequently, breaks = bins, col = 'blue', border = 'white', xlab = "Cases")

})

output$fylke <- renderPlot({

y<-Newcases2020_sum$month

z<-Newcases2020_sum$sumcases

plot(x=y, y=z, xlab = "Month", ylab = "Cases")

}) }

Run the application

shinyApp(ui, server)

AntoineSoetewey commented 3 years ago

Hello,

I want to publishing a data on shinaapp, i faced with the below error on R, "Error in func(fname, ...) : app.R did not return a shiny.appobj object" And in the shinyapp i faced with "Error in value[3L] : could not find function "%>%" Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted"

This is my code:

df1 <- cases2020 %>% filter(cases<500)

library(tidyverse) library(shiny) library(ggplot2)

Define UI for application that draws a histogram

ui <- fluidPage(

Application title

titlePanel("Old Faithful Geyser Data"),

sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30) ),

mainPanel(
  plotOutput("distPlot") ,
  plotOutput ("fylke")
)

) )

server <- function(input, output) {

output$distPlot <- renderPlot({

Cases_Frequently    <-df1$cases
bins <- seq(min(Cases_Frequently), max(Cases_Frequently), length.out = input$bins + 1)

hist(Cases_Frequently, breaks = bins, col = 'blue', border = 'white', xlab = "Cases")

})

output$fylke <- renderPlot({

y<-Newcases2020_sum$month

z<-Newcases2020_sum$sumcases

plot(x=y, y=z, xlab = "Month", ylab = "Cases")

}) }

Run the application

shinyApp(ui, server)

Hello,

Before trying to publish your app, is your app working locally (on your computer)?

It seems to me that you run df1 <- cases2020 %>% filter(cases<500) but you don't import the dataset.

Regards, Antoine

saeedraeisi commented 3 years ago

Thank you for your time and response.  yes, it is working on my PC, after i click on number 2(below picture) it is published on the shiny app. but when i want to run it on shinyapp i faced with the "Error in value[3L] : could not find function "%>%"Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted"

Best Regards,Saeed Raeisi

On Monday, May 24, 2021, 11:30:51 AM GMT+2, Antoine Soetewey ***@***.***> wrote:  

Hello,

I want to publishing a data on shinaapp, i faced with the below error on R, "Error in func(fname, ...) : app.R did not return a shiny.appobj object" And in the shinyapp i faced with "Error in value[3L] : could not find function "%>%" Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted"

This is my code:

df1 <- cases2020 %>% filter(cases<500)

library(tidyverse) library(shiny) library(ggplot2)

Define UI for application that draws a histogram

ui <- fluidPage(

Application title

titlePanel("Old Faithful Geyser Data"),

sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30) ), mainPanel( plotOutput("distPlot") , plotOutput ("fylke") )

) )

server <- function(input, output) {

output$distPlot <- renderPlot({ Cases_Frequently <-df1$cases bins <- seq(min(Cases_Frequently), max(Cases_Frequently), length.out = input$bins + 1)

hist(Cases_Frequently, breaks = bins, col = 'blue', border = 'white', xlab = "Cases")

})

output$fylke <- renderPlot({ y<-Newcases2020_sum$month

z<-Newcases2020_sum$sumcases

plot(x=y, y=z, xlab = "Month", ylab = "Cases")

}) }

Run the application

shinyApp(ui, server)

Hello,

Before trying to publish your app, is your app working locally (on your computer)?

It seems to me that you run df1 <- cases2020 %>% filter(cases<500) but you don't import the dataset.

Regards, Antoine

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

AntoineSoetewey commented 3 years ago

Thank you for your time and response.  yes, it is working on my PC, after i click on number 2(below picture) it is published on the shiny app. but when i want to run it on shinyapp i faced with the "Error in value[3L] : could not find function "%>%"Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted"

The error could not find function "%>%" means that the dplyr package is not correctly installed or loaded. Can you try again by fixing this issue first?

saeedraeisi commented 3 years ago

It did not work.can I share my screen via zoom?

I  use the df1 from R script. and didnt use the file directly to the app.R.  may the error be because of this?

Best Regards,Saeed Raeisi

On Monday, May 24, 2021, 12:00:44 PM GMT+2, Antoine Soetewey ***@***.***> wrote:  

Thank you for your time and response.  yes, it is working on my PC, after i click on number 2(below picture) it is published on the shiny app. but when i want to run it on shinyapp i faced with the "Error in value[3L] : could not find function "%>%"Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted" Best Regards,Saeed Raeisi On Monday, May 24, 2021, 11:30:51 AM GMT+2, Antoine Soetewey @.***> wrote: Hello, I want to publishing a data on shinaapp, i faced with the below error on R, "Error in func(fname, ...) : app.R did not return a shiny.appobj object" And in the shinyapp i faced with "Error in value[3L] : could not find function "%>%" Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> Execution halted" This is my code: df1 <- cases2020 %>% filter(cases<500) library(tidyverse) library(shiny) library(ggplot2) Define UI for application that draws a histogram ui <- fluidPage( Application title titlePanel("Old Faithful Geyser Data"), sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30) ), mainPanel( plotOutput("distPlot") , plotOutput ("fylke") ) ) ) server <- function(input, output) { output$distPlot <- renderPlot({ Cases_Frequently <-df1$cases bins <- seq(min(Cases_Frequently), max(Cases_Frequently), length.out = input$bins + 1) hist(Cases_Frequently, breaks = bins, col = 'blue', border = 'white', xlab = "Cases") }) output$fylke <- renderPlot({ y<-Newcases2020_sum$month z<-Newcases2020_sum$sumcases plot(x=y, y=z, xlab = "Month", ylab = "Cases") }) } Run the application shinyApp(ui, server) Hello, Before trying to publish your app, is your app working locally (on your computer)? It seems to me that you run df1 <- cases2020 %>% filter(cases<500) but you don't import the dataset. Regards, Antoine — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

The error could not find function "%>%" means that the dplyr package is not correctly installed or loaded. Can you try again by fixing this issue first?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

AntoineSoetewey commented 3 years ago

It did not work.can I share my screen via zoom?

I  use the df1 from R script. and didnt use the file directly to the app.R.  may the error be because of this?

Best Regards,Saeed Raeisi

Yes. You refer to a dataset in your app that is not available outside of your environment. So your app cannot use that dataset.

So you must publish your data as well. The easiest way is to host the dataset online as a csv file and then import it via the url (at the beginning of your code).

Hope this helps.

Regards, Antoine

andrea83ny commented 3 years ago

Hi, this is a great article, thank you for sharing it. I have two questions please.

  1. I developed a shiny app in my local computer that queries and source the data from databases I created and saved in my PC. How can I still use and access the data in my database if I publish the app?
  2. My shiny app is quite big so I organized it over multiple files. Meaning, the main file has the code that defines all the pages and tabs, but the code where I developed each page is in separate R files. How can I deploy it in this case ? Thank you, Andrea
AntoineSoetewey commented 3 years ago

Hi, this is a great article, thank you for sharing it. I have two questions please.

  1. I developed a shiny app in my local computer that queries and source the data from databases I created and saved in my PC. How can I still use and access the data in my database if I publish the app?
  2. My shiny app is quite big so I organized it over multiple files. Meaning, the main file has the code that defines all the pages and tabs, but the code where I developed each page is in separate R files. How can I deploy it in this case ? Thank you, Andrea

Dear Andrea,

  1. Did you try to publish the databases as well (when you published your app)? If this doesn't work you'll probably need to host the databases on a website and import the data from this website. This is what I did for one of my app: the data is hosted on my personal website and the shiny app reads the data from the URL.
  2. That shouldn't be a problem: if your app is working locally on your computer you simply have to publish all files.

Hope this helps.

Regards, Antoine