I've tried this code to create a clickable hyperlink in Shiny Dashboard, but the image doesn't show up for some reason (I get a question mark kind of an icon, but it's hyperlinked)
`dashboardBody(
tabItems(
tabItem("icratio",
fluidRow(
a(img(src="image.png"), href="https://google.com")
)
)
)
)`
What could be the problem?
Putting tags$a should work.
tabItem("icratio",
fluidRow(
tags$a(img(src="image.png"), href="https://google.com")
)
)
Related
As shown in the below image, I have a problem with a ghost tab that appears at the end of my navbar page.
The ghost tab disappears when the code below at the end of ui is deleted. The code is related to the loading sign. How can I fix this?
hidden(
div(
id = "app-content"
#p("")
)
)
I fixed this by moving the mentioned code to right after ui <- fluidPage(.
ui <- fluidPage(
hidden(
div(
id = "app-content"
#p("")
)
),
is there any way to show all of the contents in the mainPanel only when the user clicks the action button? ive been searching the internet for awhile for the answer but couldn't really find an answer. i know i can use hidden - it works on smaller elements inside the mainPanel, such as showing a picture on click but doesn't work on the whole mainPanel itself. any suggestions? finding a way to wrap the whole main panel inside a hidden instead of each element in the mainPanel wrapped in a hidden would be easier i think but i can't seem to find a way to make it work.
in dashboard body:
fluidRow(
column(12, actionButton("analyze", "Fetch Data!", width = "100px"))),
hidden(
mainPanel(
hidden( (htmlOutput("artistpic")), // this works fine & shows on button click
infoBoxOutput("approvalBox"))
)),
server:
pic <- eventReactive(input$analyze2, {
print(get_id_picture()[3])
url = toString(get_id_picture()[3])
print(url)
url
})
output$artistpic <- renderText({c('<img src="',pic(),'"width="17%" height="17%">')})
This is easy with shinyjs.
Just surround mainPanel() with a div() tag so that you can use it's id for toggling it's visability and start the app with the div tag hidden using hidden() like in the following example:
# ui.R
fluidPage(
useShinyjs(),
actionButton("toggle.main.button", "Toggle Main"),
div(id = "main",
mainPanel(
p("This paragraph is in main."),
p("This one too!")
)
) %>% shinyjs::hidden()
)
# server.R
library(shinyjs)
function(input, output, session) {
# Toggling visability of main on button click.
observeEvent(input$toggle.main.button, {
shinyjs::toggle("main")
})
}
I have a button in my ui.R that I want to be shown only when "Summary" tab is selected, so I thought of this code
fluidRow(
column(4,
column(12,id="sub",
actionButton("submit", "SUBMIT", width = "100%"))),
column(8,
bsCollapse(id = "collapse7", open = "Results",
bsCollapsePanel("Results",
tabsetPanel(
tabPanel("Summary",
tags$script(HTML("document.getElementById('sub').style.visibility = 'visible';")))
tabPanel("Plot",
tags$script(HTML("document.getElementById('sub').style.visibility = 'hidden';"))))
))))
The problem is, the button is hidden even though in my first tab it should be visible and also when i go to Plots and back to Summary, the button stays hidden.
After looking at: How to use tabPanel as input in R Shiny?
I decided to play with observeEvent and the input$tabset option. The result is 100% working and it's really simple. Here's the code:
observeEvent(input$choices, {
choice = input$choices
if(choice == "Summary")
{
runjs(
"document.getElementById('submit').style.visibility = 'visible';"
)
}
else
{
runjs(
"document.getElementById('submit').style.visibility = 'hidden';"
)
}
})
Also, I found out why my previous code wasn't working, it was due to the fact that when the UI was initialized, the button element kept the last style modification (the hidden one) and it didn't change depending on the tab I have selected, since its not reactive.
is there a way to add a new line when putting text through the UI?
I currently have something like
mainPanel(
h3("This is my app!\n\n"),
h4("Download your data using the choose file button\n\n"),
h4("Thank you for using the app!")
)
but the new lines don't seem to be working.
\n doesn't work in shiny app.
For the new line, you could use HTML tag <br/>:
mainPanel(
HTML(
paste(
h3("This is my app!"),'<br/>',
h4("Download your data using the choose file button"),'<br/>',
h4("Thank you for using the app!")
)
)
)
I have created quite a large app that I now want to extent by introducing tabs. So far I have, as an example:
ui.R
shinyUI(
#OLD CODE
)
server.R
(
#OLD CODE
)
What I would like to do:
ui.R
shinyUI(
tabsetPanel(
"Tabs",
tabPanel("Old Code",value="tb1"),
tabPanel("New Code",value="tb2"),
id = "nlp"
),
if (id=="tb1") {
#OLD CODE
} else if (id=="tb2") {
#New Code
} else {
#Do nothing
}
How do I get the if function to recognise id as a variable?
When I run the script it comes up with the error object 'id' not found. So then I've tried input$id and output$id with no avail.
I have also tried going to the server.R and tried
Server.R
output$id <- renderText("id")
also didn't work when trying to bring that back into the UI
and I have also tried
Server.R
output$id <- reactive({input$id})
this also didn't work when I tried to use it in the UI. Where am I going wrong and how can I use the Id variable in the UI?
Thanks
Based on the Shiny Tabsets example, you should be putting the UI elements into each call to tabPanel, like so:
shinyUI(
tabsetPanel(
tabPanel(
title = "Old Code",
plotOutput('plot1'),
plotOutput('plot2')
),
tabPanel(
title = "New Code",
tableOutput('table')
),
id = "nlp"
)
)
Unless you are trying to do more than necessary, your code does not need to know what tab the client has selected. I may be wrong (please do not think I'm an authority on shiny), I think the elements within the not-selected tabs are not unnecessarily recalculated (unless dependencies exist and require it).