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.
Related
My code is following:
ui <- fluidPage(
titlePanel("My Shiny App"),
sidebarLayout(
sidebarPanel(
h4("Installation"),
p("Shiny is available on CRAN, so you can install it on the usual way from your R console:"),
div("install packages('shiny')", style="color:red"),
img(src="C:/Users/asus/Desktop/App-1/rstudio.png", height=70, width=200)
),
mainPanel()
)
)
The picture does not appear properly. Only an empty box appears where the picture should appear.
I am currently trying to generate a Shiny App that at the press of a button generates and downloads data for a user. I have a user defined function that pulls data from some places, analyzes, and creates a .csv comprised of numerous tables.
The bottleneck I'm running into is successfully taking this .csv file comprised of multiple tables and allowing it to be easily downloaded. I have tried applying the solution presented here, but when I run the application script, all of the data is generated from the button but it doesn't bring up the download window as I'd hoped. Is there a way of using downloadHandler and link it to something other than a downloadButton or downloadLink function?
Current UI Function:
ui <- dashboardPage(
dashboardHeader(title = "Download Center"),
dashboardSidebar(
sidebarMenu(id="mytabs",
sidebarMenuOutput("menu")
)
),
dashboardBody(tabItems(
tabItem(tabName = "DataHarah", h2("Download Your Data Here"),
textInput(inputId='startyear', label='What is the first year?'
,value=2021, width = NULL, placeholder = "Inputs should be
a four digit year (e.g. 2022)."),
textInput(inputId='endyear', label='What is the last year?'
,value=2022, width = NULL, placeholder = "Inputs should be
a four digit year (e.g. 2022)."),
actionButton("do", "Generate & Download Your Data!")
))
))
Current Server Function & Initialization:
observeEvent(input$do,
{DataTalk(input$startyear,input$endyear) # function that generates a csv file
# containing multiple tables.
output$downloadData <- downloadHandler( #download handler that may not be connected properly.
filename = c('mycsv.csv'),
content = function(file){
file.copy('mycsv.csv',file)})})}
shinyApp(ui, server)
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)
I've been trying to add a graph I made to my shiny layout but when I run the project it shows me this error.
I've got the following code for the serve.R:
library(shiny)
df <-read.csv('./CSV/data.csv')
shinyServer(function(input, output) {
output$scatterPlot <- renderHighchart({
hchart(df, "scatter",
hcaes(x=df$revenue,y=df$users,group=df$name_group))
})
})
And for the ui I got:
library(shiny)
library(shinydashboard)
library(shinycssloaders)
titlePanel("my_app")
header <- dashboardHeader(title = "my_app" )
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Overview", tabName = "overview", icon = icon("book-open"))
)
body <- dashboardBody(
tabItems(
tabItem("overview",
fluidRow(
box(
title = "revenue_vs_user", status = "primary",
withSpinner(highchartOutput("scatterPlot"))
))
)
))
shinyUI(dashboardPage(header, sidebar, body, skin = "blue"))
All answers I've seen on this mistake say that it happens because the data is not being read correctly but in my enviroment variables the data appears, so it is being read. Thanks for the help!
I had the same problem. When developing the app and testing if the CSV would upload, R studio showed the CSV data properly uploaded and stored in the Environment variables. But when I would select Runn App, I would get the same error.
I also use a data sub-folder structure. I also setup an R Project in the folder above my app. So the folder structure looked like this:
./Project/app/data
where the Project file was in the Project folder, app.R file was in the app folder, and the CSV I was trying to upload was in the data folder.
I then tried putting the Project file in the app folder instead. I also updated the relative file path for read.csv in the app to reflect the new working directory. For some reasons this worked. I don't know why.
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 :)