Integrating Seurat CellSelector function inside a shiny app - r

I'm writing a ShinyApp which presents Seurat data. I want the app users to be able to select specific cell for later comparison and analysis. I want the cellSelcetor to be activated when a button is pressed, so I tried:
observeEvent(input$selectCells, {
output$clusterCompPlot <- renderPlot({CellSelector(plot = chosenClusterPlot)})
})
The problem is, I think, that cellSelector is already based on shiny, so I'm currently getting the following error:
Error in shiny::runApp: Can't call runApp() from within runApp(). If your application code contains runApp(), please remove it.
Is there any way to integrate this feature into my app?
Thanks!

Related

Auto-Update Data for R Shiny Dashboard

so I thought I had figured this out thanks to previous help (Updating R shiny data), but I have come across more issues. I didn't notice these issues since I got busy doing other things in my job. But turns out it is not auto-updating the app on shinyapps.io. I'll post the test code I have made in the server section:
dftest<-reactiveFileReader(1000,session,"Crop Registration 2022.xlsx",readFunc = read_excel,sheet = "CSV")
output$table2<-renderTable(
{
dftest2<-filter(dftest(),Variety=="Test1", Week>25 )
dftest2
}
)
What I found is after publishing the app on shinyapps.io any changes made to the excel sheet "CSV" do not show up. What I want is I can add data to the original excel sheet the app on shiny apps auto updates with the new data. Am I approaching this problem completely wrong? Or is it even possible via shinyapps.io ?

R Shiny - Run application in background and issue UI controls with code

I am writing a vignette for my Shiny application package. At the beginning of my vignette, I source a file called screenshots.R that produces nice screenshots of my application. I am producing them like so:
webshot::appshot(mypackage::run_datepicker_app(),
file = "man/figures/datepicker.png", vwidth = 500, vheight = 200)
This works great and it gives me a great screenshot of what is - in this case - a couple dateInput fields. However, I'd like to be able to get a screenshot of the dateInput in use (say, with the calendar selection exposed).
Is there a way to issue commands to the application object in a script so I can get screenshots of the application in use, rather than having to do it manually?
Have you tried using ShinyDriver from the shinytest package?
You can use shinytest to have a headless browser run the app, interact with it, and take screenshots programmatically. If you don't have phantomJS installed, you'll need to run shinytest::installDependencies() before using ShinyDriver. All you need to do is point it to a directory containing a shiny app (in my case, the folder is 'myApp').
install.packages("shinytest")
shinytest::installDependencies()
app <- shinytest::ShinyDriver$new("myApp")
app$takeScreenshot("screenshot1.png")
button <- app$findElement("#button")
button$click()
Sys.sleep(1)
app$takeScreenshot("screenshot2.png")
app$stop()
I am starting the app in a headless browser, taking a screenshot, finding the button with the id 'button', clicking it, and taking another screenshot, then closing the app. Navigate to specific elements using "#id", where id is just the id you gave the shiny input. You can specify a file path to a png file in the takeScreenshot calls, so that you can then use them in your code elsewhere. Note that you may need to use Sys.sleep to stop the screenshots from being taken before the UI updates.

R Highcharter: How to show No Data to Display message?

I have created a dynamic Highchart in R Shiny App. I want to display a customized message when there is no data to display the charts.
In Highchart API, there is setOptions where you can display the customized message. Something similar is mentioned in this question: How to display No Data Available Message in highcharts.
But I haven't found anything similar in Highcharter.
Any solutions?
Within your renderHighcharter function, you can put something like this:
shiny::validate(
need((nrow(DataSet()) != 0), "No data available based on your selection")
)
You can have as many validate functions that you need and make them as complicated as you need to help the user troubleshoot.

Automatically reloading shiny app when error occurs

This is a follow-up for my previous question Automatically reloading shiny app when add changes.
The solution options(shiny.autoreload = TRUE) works perfect when you want to automatically see changes on the browser which you put in the code.
However, the potential problem occurs when you save unfinished/corrupted file. For example, the following ui code lacks a , sign after the titlePanel function:
fluidPage(
titlePanel("Old Faithful Geyser Datass")
sidebarLayout(...
When you save such a file, you will get an error on your browser
ERROR: Error sourcing your_path/ui.R
R console will help detect the problem with the , sign. My impression was that if I improve my code and save the file, it should reload the browser and show my app correctly. Unfortunately, it doesn't do it.
Interesting thing is that an error in the app does not terminate the connection with the browser. To confirm my word, just reload the app manually using reload button in the browser (after improving your code).
Therofore, I examined how this shiny.autoreload option works. As I expected, it checked the time of file modification and then execute reload function. Then reload function send a message via sendMessage to the addMessageHandler:
addMessageHandler('reload', function(message) {
window.location.reload();
});
So it seems that after improving your code the function should be reexecuted, but it's not gonna happen.
To summarise, I think it's not possible to change it without major changes in shiny but maybe I am wrong. Thanks for any suggestion.
PS.You can manipulate example code here to see the problem.

Notifying user about his bad input in Shiny app

Let's take a look at one of the demos.
runExample("09_upload")
I am using the supplied file to perform some computations and to display an aggregated performance across all uploaded files. Therefore, I use something like
tryCatch(compute.smth(), error=function(e){})
so that the displayed result is not affected by the bad input. However, I'd like to indicate somehow that uploading the bad file lead to an error, notifying the user about the problem with his input. It'll be something like
tryCatch(compute.smth(), error=badFile())
where badFile() should modify some displayable output. Any ideas?
As a last resort, this is probably an option, but I'd like some native Shiny.
You can show alerts like below with the ShinySky package: https://github.com/AnalytixWare/ShinySky
You can install the package using
install.packages("devtools")#if not alrady installed
devtools::install_github("ShinySky","AnalytixWare")
Place a shinyalert(id) in the ui.R for where you want the alert to appear.
In your server.R
Make sure you have a 3 parameters funciton being passed to shinyServer e.g.shinyServer(function(input, output,session) {
use showshinyalert(id,HTMLText,session) to show the alert. Clicking on the alert will dismiss it.
See this gist for example https://gist.github.com/xiaodaigh/7707701
Run this too see an example
shinysky::run.shinysky.example()

Resources