how do you integrate 2 different shiny apps in one - r

I have two shiny apps with ui and server compoents. I need to create one app and be able to open the each application with tabs. Clicking on one tab will bring the app.
first app is like this:
ui <- pageWithSidebar(....)
server <- function(input, output,session) {....}
second app is something like this:
shinyUI(....)
server <- function(input, output, session) {.....}
How could I create one app and refer to these apps from tabs within one app?

As far as I know, this could be achieved in two ways.
Simple shiny app:
You can create tabs using tabPanel(title, ...) function and then wrapping all the tabPanel()s inside a tabsetPanel() function.
So, in your case you can put all the UI elements of your first app inside the first tabPanel('unique_title') and so on.
This will help you create multiple independently viewable sections.
You can refer these two links to know more
http://shiny.rstudio.com/reference/shiny/latest/tabPanel.html
As #Michal suggested, using shinydashboard:
shinydashnoard is another package that you will have to install in order to use this feature of shiny. It basically has a predefined structure with a header, a sidebar and a body.
The basic structure is shown below:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashbaordSidebar(),
dashboardBody()
)
server <- function(input,output,server){...}
Normally, dashboardSidebar() is used for navigation. However, it can contain menuItem() that behave like tabs in a tabPanel().
For your case, you can add multiple menuItem()s inside sidebarMenu() as shown below
Updated Code
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
menuItem("first_app", tabName = "first_app"),
menuItem("second_app", tabName = "second_app")
)
),
dashboardBody(
tabItems(
tabItem(tabName = "first_app",
h2("First App Content")
),
tabItem(tabName = "second_app",
h2("Second App Content"))
)
)
)
server <- function(input,output,server){}
shinyApp(ui,server)
This will create a basic dashboard page with 2 menu items.
You can also refer to link below to know more about the shinydashboard structure
https://rstudio.github.io/shinydashboard/structure.html
I hope this helps :)

Related

How to disable all Shiny UI elements, including a downloadButton

This answer explains how can one disable/enable all UI elements in a Shiny app.
Among the two solutions given, the one I am interested in uses the shinyjs package (I'd rather not play with javascript directly).
My problem is that UI elements of the class downloadButton are not listed as elements of input.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
tagList(
downloadButton("downloadBtn", "Download button"),
actionButton("printBtn", "Print and disable all members of input")
)
)
server <- function(input, output) {
observeEvent(input$printBtn, {
print (names(input))
for(n in names(input))
shinyjs::disable(id=n)
})
}
shinyApp(ui = ui, server = server)
When I click on the "Print all members of input", only "printBtn" is printed ("downloadBtn" is not).
Hence, since downloadButton is not a member of input, disabling it by looping over all the elements of input - and disabling them one by one does not work.
Is there an elegant workaround that can be used in order to disable all of the elements?

Is it possible to display an info text when hovering over a R shiny selectInput?

I am currently building a shiny app to build biological networks. To build them, you can choose between many different parameters, which i included in different selectInputs or numericInputs.
Is it possible to have some kind of info text, when hovering the mouse over those input fields? I dont want to add 3-4 sentences of text to the title of each select/numericInput.
Thanks :)
If you don't mind an extra package dependancy then you can use bsTooltip from the shinyBS package. Note that the hover tooltip sometimes doesn't show up unless you click on the input in the RStudio viewer pane, but if you run your app in your browser, the hover trigger should work:
library(shiny)
library(shinyBS)
ui <- fluidPage(
selectInput("input1", "Select input", c("choice1", "choice2")),
bsTooltip(id = "input1",
title = "Here is some text with your instructions")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)

How to display live poll results using R Shiny dashboard

I apologize for a very novice question.
I'm learning to use R shiny dashboard to display live infographics of polls performed through google forms.
This is the trial form: https://forms.gle/pixQ2pui5Qmgh9A4A
And this is the url that may be used to extract the .csv output of its responses:
https://docs.google.com/spreadsheets/d/1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo/export?format=csv&id=1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo&gid=1120079968
I understand that the reactiveFileReader() function should update the data continuously, but this does not seem to work, and the plot does not get updated unless the page is refreshed manually. How can the data be made to update itself continuously instead?
Thanks all!
library(shiny)
library(shinydashboard)
ui <- shinyUI(
dashboardPage(
dashboardHeader(title = "Data streaming"),
dashboardSidebar(
menuItem("Plot")
),
dashboardBody(
fluidRow(
box(plotOutput("histogram"))
)
)
)
)
server <-
shinyServer(function(input, output, session){
form.url = "https://docs.google.com/spreadsheets/d/1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo/export?format=csv&id=1yS1l3Scvw98ueg5ZZe4021a3y5gMqe6FOP-ZrQIvHBo&gid=1120079968"
dat <- reactiveFileReader(1000,
session,
filePath=form.url,
readFunc = function(filePath) {
read.csv(url(filePath))
})
output$histogram <- renderPlot({
hist(dat()$N, cex.main="", xlab="Poll", breaks=5)
})
})
shinyApp(ui, server)
formr is a free solution to live poll visualisation with R. They can host your polls but you can also host your own.

Giving Titles to side plots in Shiny with Fluidrow

How to give titles in Shiny for two side plots, I am trying to do something like following, which is definitely giving me error
shinyUI(
titlePanel("Hello Shiny!"),
mainPanel(
fluidRow(
splitLayout(cellWidth(50%,50%),
tableOutput("Table1", tags$b("Title1")),
plotOutput("Plot",tags$b("Title2)))))
Here is the solution for you:
library(shiny)
ui <- basicPage(
fluidRow(
column(6,box("Title 1",tableOutput("Table1"))),
column(6,box("Title 2",plotOutput("Plot")))))
server <- function(input, output) {
}
shinyApp(ui, server)
It is enough if you just type the text in column container before ..output(..)
I have improved bit your code by replacing splitLayout() to column containers which divide/split the ui into two, same size containers (column(6)=50%) and addition of box(), so your outputs are held there and title will be attached to it (to the box)

Combine some shiny apps to one shiny dashboard

I have several shiny apps, and now I want to create a dashboard for these apps. I don't want to change the original apps.Just want to create another ui.R and server.R. And integrate the other apps into it. Like the following structure.
#ui.R
ui <- dashboardPage(
dashboardHeader(title = "App User Analyse"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "Dashboard",
***app1***
),
# Second tab content
tabItem(tabName = "widgets",
***app2***
)
)
)
)
I'm new to shiny and shiny server. I'm not sure if there is a way to achieve this. If yes, could any one give me a small example? Thank you!
My first instinct is that you can't simply copy all the apps code into one place and expect it to work, you'll have to do a little bit of work to integrate them all together. For example, if two of your apps have an input field with id "foo", then you can't have both of them unchanged in one shinydashboard app because you cannot have multiple elements with the same id. This is just a very simple example of why you can't simply concatenate all the code together.

Resources