I have two buttons in my U.i file
submitButton("Analysis"),width=6,downloadButton('downloadData', 'Download Data'))
Which gives the following output as the app
However I am trying to align these buttons so that the download data is right aligned and the analysis button is on the left, instead of how it looks now. How do i go about this?
You can do the following. Please look into shiny 4 small textInput boxes side-by-side also
library(shiny)
ui =fluidPage(
div(style="display:inline-block",submitButton("Analysis"),width=6),
div(style="display:inline-block",downloadButton('downloadData', 'Download Data'))
)
server = function(input, output, session){}
runApp(list(ui = ui, server = server))
Related
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'm trying to show a logo in my Shiny app, but when i try to see i only can see a small icon, but not the image, this is my code:
library(shiny)
ui <- fluidPage(
mainPanel(
img(src='C:/Users/carlo239/image[![enter image description here][1]][1]/Capture2.jpg',
align = "right", height = '300px'),
### the rest of your code
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
And this is the issue, i tried to reload, but is not working,
I know that the image is ok, because if i click on Download i get the same image, but i'm unable to see in my outputs. THANKS !!
There are two ways:
Put the file in the www folder of your app (as suggested by #YBS). That is in most cases the recommended solution.
"Register" your folder as resource folder for your app (see below). However, that solution is intended to help package authors make resources available to the package's components. Also be aware that absolute paths can pose problems when you deploy your app.
library(shiny)
ui <- fluidPage(
mainPanel(
img(src='/foo/Capture2.jpg',
align = "right", height = '300px'),
### the rest of your code
)
)
server <- function(input, output, session) {
addResourcePath("foo", "C:/Users/wherever/your/file/may/be/located")
}
shinyApp(ui, server)
I've got a Flexdashboard-based Shiny application with several tabs, and within each tab, grids of multiple plots. Performance is a bit of an issue, particularly when deployed on the free Shiny Server.
Initially, the main issue was that clicking each tab would require re-rendering of the plots. I set the suspendWhenHidden option to be FALSE, and this helps - Now switching the input has a slow delay to load all the plots, but at least when navigating the UI, performance is snappy.
This got me thinking, however - is there any way to achieve a hybrid of the two behaviors? So say I'm on an active tab which just produces a single plot. This plot renders quickly. Can we tell shiny to render this plot, display it to the user, and then in the background, continue loading all the elements of the other tabs? As it stands now, the active tab will not finish rendering the plot until all plots on the hidden tabs are also rendered.
In summary, a hybrid suspendWhenHidden = FALSE and TRUE:
Render the active tab elements first, display to the user, then
Continue rendering the elements on the hidden tabs
I thought perhaps setting priority might achieve this, but it doesn't seem to work. Any thoughts or suggestions?
Here's a minimal reproducible example. The goal would be for the first plot (in tab 1) to render and appear before beginning rendering of the second plot (in tab 2) - But the plot should start rendering in tab 2 without requiring a click of tab 2.
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
numericInput('n', 'Size', 10)
),
mainPanel(
tabsetPanel(
tabPanel("Tab1", plotOutput("plot1")),
tabPanel("Tab2", plotOutput("plot2"))))
)
)
# Define the server code
server <- shinyServer(function(input, output, session) {
output$plot1 <- renderPlot({plot(1:input$n)},height = 400,width=800)
output$plot2 <- renderPlot({ Sys.sleep(5); plot(1:input$n,col="red")},height = 400,width=800)
outputOptions(output, "plot2", suspendWhenHidden = FALSE)
})
# Return a Shiny app object
shinyApp(ui = ui, server = server)
There is two ways to achieve this
Load all the tabs and then show the output
Use eventReactive to activate the other tabs
For the first option just put below additionally
outputOptions(output, "plot1", suspendWhenHidden = FALSE)
and if you want reactivity write eventReactive functions for each tab.
I am finally trying to make a Shiny app. I am trying to upload a .xlsx file to the app, and then apply some analysis and download the output as a separate .xlsx file. The code for analysis and taking output works when run directly outside Shiny and I use it on daily, so I am simply trying to call it via source and save the duplicated work. Here is what I am trying with Shiny.
I was having problems in calling the file from the W2S.R script, while avoiding errors. I found a way to avoid the errors. The below code is a barebones model of that. However, now I cannot get the actual input to work (Output works fine, one table output on-screen and one XLSX output off-screen).
I am using W2S <- input$W2S1 inside W2S.R script, but it is not recognising the variable input, which it does if used in the server function directly. How do I get it to work inside the script? Or is there any other workaround?
library(shiny)
ui <- fluidPage(
titlePanel(h1("Goods In Transit Analysis", align="center")),
sidebarLayout(
sidebarPanel(
fileInput("W2S1", label="Select GIT W2S file")
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output) {
output$contents <- renderTable(if(is.null(input$W2S1)){return(NULL)}
else{source("./W2S.R")})
}
shinyApp(ui = ui, server = server)
I will update once I get the input to work. Please help.
EDIT: Made some progress, as noted above. So updated the new code.
Finally nailed it. I needed an observe function and use the $datapath argument.
library(shiny)
ui <- fluidPage(
# Application title
titlePanel(h1("Goods In Transit Analysis", align="center")),
# Sidebar iputs
sidebarLayout(
sidebarPanel(
fileInput(inputId="W2S", label="Select GIT W2S file")
),
# On Screen output
mainPanel(
h3(textOutput("filePath")),
tableOutput("contents")
)
)
)
# Underlining code for output
server <- function(input, output) {
observe({
source("./Code/W2S.R")
W2S <- input$W2S
output$contents <- renderTable(if(is.null(W2S)){return(NULL)}
else{W2S_F(W2S$datapath)})
})
}
# Run the application
shinyApp(ui = ui, server = server)
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)