I have a app that works just fine without adding shinycssloaders package. But for some reason, after I added the package and added the lines (see below), it stopped working if I deploy it with shinyapps.io. The app runs fine locally, just wouldn't let me deploy it.
# load the library
library(shinycssloaders)
withSpinner(plotOutput("my_plot"))
# if you have `%>%` loaded, you can do plotOutput("my_plot") %>% withSpinner()
The error message I'm getting in the log is attached down below, but I have package shinycssloaders, and I've tried downloading it from CRAN and github, but neither works.
2019-05-13T16:41:39.317482+00:00 shinyapps[890504]: Using pandoc at /opt/connect/ext/pandoc2
2019-05-13T16:41:39.538904+00:00 shinyapps[890504]: Listening on http://127.0.0.1:46817
2019-05-13T16:41:43.893648+00:00 shinyapps[890504]: Warning: Error in withSpinner: could not find function "withSpinner"
2019-05-13T16:41:43.908035+00:00 shinyapps[890504]: 68: div
2019-05-13T16:41:43.908036+00:00 shinyapps[890504]: 67: mainPanel
2019-05-13T16:41:43.908034+00:00 shinyapps[890504]: 69: tags$div
2019-05-13T16:41:43.908032+00:00 shinyapps[890504]: 70: tag
I'm sure this work because it is on their github page, but I'm not sure what I did wrong. Worst case scenario, I'll just get rid of it so it's not a huge issue, but it'd be cool if I can use it. Any help is appreciated!
EDIT
So I attached a sample code, feel free try to deploy it, did't work for me. But works fine locally (since it's a sample app, the loading spinner is extremely quick, but you'd still be able to see it).
library(shiny)
library(shinycssloaders)
ui <- fluidPage(
actionButton("go", "Go"),
numericInput("n", "n", 50),
withSpinner(plotOutput("my_plot"))
)
server <- function(input, output) {
randomVals <- eventReactive(input$go, {
runif(input$n)
})
output$my_plot <- renderPlot({
hist(randomVals())
})
}
shinyApp(ui, server)
Since the log says Warning: Error in withSpinner: could not find function "withSpinner"
I went ahead added the package name in front of withSpinner function, so now in the UI function, it should be
shinycssloaders::withSpinner(plotOutput("my_plot", height = 600))
and it works perfect with deploy. Although it seems bizarre, because I indeed attached library(shinycssloaders). In my actual app, I attached it in server.R file, perhaps that's why.
Related
I'm having an issue with the running of a R shiny app. Here's what I do:
open RStudio
load the shiny code (e.g. app.R)
set the wd
library(shiny)
press on "Run App"
Then nothing happens.
And if I try to terminate the execution, R does not answer anymore and says to force the closing of RStudio.
Here's one of my codes (I tried some, so I don't think this is the issue, but I report one anyway):
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
titlePanel("Un'applicazione con uno slider"),
sidebarLayout(
h1("Sposta lo Slider!"),
sliderInput("slider1", "Spostami!", 0, 100, 0)
),
mainPanel(
h3("Valore dello slider:"),
textOutput("text")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$text <- renderText(input$slider1)
}
# Run the application
shinyApp(ui = ui, server = server)
Do you have any advice to give me in order to make anything happen? I have no errors shown, so I don't know what to do...
I just see "runApp(...mypath.../app)" and blank space after it.
Thank you in advance.
Edit 1:
I also tried this, but nothing happened (as before):
library(shiny)
runExample("01_hello")
Edit 2: Copy-pasting the code directly in the console doen not work either
I was experiencing the same issue with R 4.1 on Windows 10. Updating all packages seems to have solved it:
update.packages(ask = FALSE, checkBuilt = TRUE)
I'm using the normal template for shiny:
library(shiny)
ui <- fluidPage(
#a lot of inputs, graphs, also uiOutput()
)
server <- function(input, output){
#sourcing and running function to generate output, making graphs
}
shinyApp(ui = ui, server = server)
When using the "Run App"-Button, deploying to shinyapps.io or selecting all code and running it, ui is not read in properly. It does not appear in the environment and the error message Error in force(ui) : object 'ui' not found is printed.
When running the code line-by-line however it works fine.
I found this post, where someone had the same error message: https://community.rstudio.com/t/error-in-force-ui-object-ui-not-found-when-deploying-app-to-server/34027, but their solution (removing shinyApp(ui = ui, server = server)) did not work for me.
After I disabled all the complex code inside server and ui, to make it match the example the error still occurred. The issue was in the code above the actual app.
I had used this line before defining ui and server:
X<-function(){} #making an empty function so the one from another script is not underlined
When commenting this out the code worked.
I would like to add hover tooltips to my input and output boxes on a shiny app that is deployed in shinyapps.io.
I found the RLumShiny package which can add tooltips and I have modified my app to accommodate this. The app works locally but when I try to deploy it to shinyapps.io I end up with the error seen below. There are no companion files to the app - just the ui.R and server.R files.
To deploy I run
library(rsconnect)
deployApp('~/sandbox/overdiag/', logLevel="verbose")
I get an error message
----- Deployment error -----
Error: C stack usage 7969336 is too close to the limit
(and a bunch of other information from the track). I've made a minimal example that produces the same error where the ui.R is
## ui.R ##
library("shiny")
library("RLumShiny") ## This package is problematic
library("shinydashboard")
library("shinyWidgets")
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
and server.R
library("shiny")
library("RLumShiny") ## Again this package
library("shinydashboard")
function(input, output, session) {
}
Now if I remove the library("RLumShiny") line then everything works fine and I can deploy it right away. I don't get information that the package is not available but maybe there is something else wrong (I have a nagging feeling that the javascript in the package might do some things that the shinyapps.io service does not like).
Now: is there an alternative approach (ie., some other package) to get hover tooltips on the shinyapps.io or can I do something else to get RLumShiny to work?
In general in shiny you can get tooltips by using tags$div in your ui.r to wrap your controls / outputs and giving it a title. So for example you could do:
tags$div(title="My tooltip", plotOutput(outputId="MyPlot"))
and you will get a tool tip. The same pattern works for controls.
Is it possible to write R Code within the shiny app while it's running? I've built a shiny app, but would like to give users the option to write their own R code in the shiny app. I want to put the console in shiny along with the viewer and a simplified environment pane. I've never seen anything like this, so before I spend a lot of time doing this I'm wondering if it's even possible. Has anyone seen something like this?
Thanks to Cory I found rfiddle, which is exactly what I'm looking for. However I can't seem to get it to work. I used the iframe that r-fiddles website says to use to embed rfiddle, but I keep getting this error message:
Error in withReactiveDomain(shinysession, { :
No handler registered for for type .clientdata_output_<iframe width="300" height="600" src="http://r-fiddle.org/#/embed/eYsWfghB/1" allowfullscreen="allowfullscreen" frameborder="0"></iframe>_hidden
Code:
library(shiny)
ui = shinyUI(
fluidPage(
htmlOutput(tags$iframe(width=300, height=600,
src='http://r-fiddle.org/#/embed/eYsWfghB/1',
allowfullscreen='allowfullscreen', frameborder='0'))
)
)
server = shinyServer(function(input, output, session) {
})
shiny::shinyApp(ui,server)
I typically use print when I'm building shinyapps as a way to check to make sure what I think should happen is actually what is happening. However, I've run into a problem where print is no longer printing to the R console when I have an app running. Here's a simple example of what I've tried:
ui <- fluidPage(
sliderInput("slider", "Slider Range",
min = 0, max = 5000, value = c(11))
)
server <- function(input, output){
print("Non-Reactive")
new <- reactive({
print("Reactive")
print(input$slider)
})
}
shinyApp(ui, server)
Within the R console, I get: [1] "Non-Reactive" and that is it. No [1] "Reactive" or [1] 11 for my slider.
I know it used to work before, but I'm not sure what changed. If there's another easier way to check/debug code for shinyapps aside from print I'd love to know my other options too.
Note: My shinyapp package is version 0.13.0. My RStudio version is 0.99.491. R is currently 3.2.2.
As jenesaisquoi mentioned, I had to use observe(new()) later in my server code in order to observe changes in the reactive() function. I must just by dumb luck never used print() in a reactive() function when testing things.