I'm working on a dashboard in Shiny and I would like to include some images (and be able to position them on the page. However, the box in which I included some text and images doesn't have any height. Does anyone know how to fix this? I've included my code and a screenshot of my dashboard.
My code (UI) (The problem is in Tab4):
dashboardBody(
useShinyjs(),
fluidRow(
tabBox(
side = 'right',
width = 12,
height = "100%",
selected = "Tab1",
tabPanel("Tab1",
dataTableOutput('table2')),
tabPanel("Tab2",
dataTableOutput('table1')),
tabPanel("Tab3",
h2("Old:"),
h4("some text to explain the datatable"),
DT::dataTableOutput('table3'),
hr(),
h2("New:"),
h4("Some more text to explain this datatable."),
DT::dataTableOutput('table4')
),
tabPanel("Tab4",
div(h2("This is an example"),
p("some text"),
h3("some header"),
p('Even more text'),
img(src='logoStackOverflow.PNG'),
p('explain something about the image'),
style ="position:absolute;
max-width:1200px;
left:30px;
top:40px;
height:100%;"),
div(img(src="logoStackOverflow.PNG"),
img(src="logoStackOverflow.PNG"),
style ="position:absolute;
border: 1px solid;
max-width:300px;
box-align:right;
position: fixed;
height:auto;
right:100px;
top:150px;")
)
)
)
)
You were very close. Replace img() with tags$img() and provide height and width as tags$img(height=100, width=100, src="YBS.png", style="text-align: right;"). Then you get the following output in tab4.
Related
I have added footer in my shiny app using html tag with fluidPage():
tags$footer(HTML(sprintf("For further information visit www.website.com",
align = "center",
style = "position:absolute; width: 100%; color: white;")
I need help making the link clickable. Can someone help me with the correct syntax in this example?
Also, any suggestions where to learn more about HTML & CSS implementation and syntax in shiny would be very useful.
You can use a HTML a Tag:
library(shiny)
ui <- fluidPage(
tags$footer(
"For further information visit ",
tags$a(
"www.google.com",
target = "_blank",
href = "https://www.google.com/"
),
style = "position: absolute; width: 100%; color: black; text-align: center;"
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
i am looking for a way to get the size of a rendered image within a webpage, which size is defined as a percentage value.
I need this because of a relative positioning of 2 images which should be invariant go the size of the browser window, as well as the zooming of the site.
I did some research and this one here describes my problem pretty well:
Button width as a percentage of parent
Quote:
"To set a percentage height, its parent element must have an explicit height."
Here are the relevant parts of my project:
<div style="display: block; width:90%; height:100%; background-color:rgba(128,128,0,0.5)">
<button style=#myStyle #onclick="#(e => doFunction(5))"> </button>
with myStyle:
myStyle = "top: -30%; left: 0%; width: 15%; height: 15%; overflow: hidden; background-color: rgba(201, 76, 76, 0.3); position: relative;"
So, i got the button within a structure, and the size of the structure is again given as a percentage with respect to its superordinate structure. (but this topmost structure then has absolute values).
Is there a way to calculating and getting the absolute values (width/height) of the first structure "while rendering"?
I hope i could explain my problem sufficiently understandable, i'm happy about any answers regarding this problem, even if the answer is "it does not work like that". Thanks!
I would do it like this:
Give your image an ID:
<div id="some-id" style="display: block; width:90%; height:100%; background-color:rgba(128,128,0,0.5)">
In JavaScript, set an Event Listener when the window is loaded:
window.addEventListener('load', function() {
//set the image's dimensions to the divs that need it
var imageDiv = document.getElementById("some-id");
var otherDiv = document.getElementById("other-div");
otherDiv.style.height = imageDiv.offsetHeight + "px";
otherDiv.style.width = imageDiv.offsetWidth + "px";
});
I have R code that generates an HTML page with image elements. The image should fill out 100% width of the column - but it not works.
# Plot 'Bar'
...
tags$tr(tags$td(
colspan="7", align="center", valign="top", width="100%",
gt::html(gt::ggplot_image(g_bar, height = 200, aspect_ratio = 1.5)))
),
...
Any ideas on how to stretch our "g_bar" on the whole column width?
Thanks!
The given script creates an action button and a slider in r shiny. If I wish to give certain attributes to {{ button }} in html script like position, margin from left, height and width, please help me with this.
<!-- template.html -->
<html>
<head>
{{ headContent() }}
</head>
<body>
<div>
{{ button }}
{{ slider }}
</div>
</body>
</html>
## ui.R ##
htmlTemplate("template.html",
button = actionButton("action", "Action"),
slider = sliderInput("x", "X", 1, 100, 50)
)
reproducible example, note that action button can be styled directly by using #action selector however slider input has container therefore positioning of the slider as such should be done at container level and cannot be done by selecting id. As far as i know css selector doesnt have equivalent of jquery :has()
library(shiny)
shinyApp(
ui <- fluidPage(
fluidRow(actionButton("action", "Action"),sliderInput("x", "X", 1, 100, 50)),
tags$head(
tags$style('#action { margin:3px;border:2px solid green;padding 20px;}
.slider-custom-format { margin:3px;border:1px solid red;}
.slider-custom-format .irs-bar,.slider-custom-format .irs-bar-edge{background:red;}'),
tags$script('$(function(){
$(".form-group.shiny-input-container:has(#x)").addClass("slider-custom-format")
})')
)
),
server <- function(input, output) {})
I have used the Plotalot extension to create different types of charts on my Joomla site. I am having issues with the margin around the piece charts in particular. I have placed the chart inside a container and although I have made the chart almost the full size of the container it leaves massive margins around the sides and bottom. I'm not quite sure how to reduce this white area around it.
Here is the CSS that I have so far for both the container and the chart, and the code for the chart itself:
#chart_42_container {
clear: right;
float: right;
margin-left: 1px;
width: 577px;
height: 400px;
}
#chart_42 {
height: 398px;
width: 575px;
}
google.load('visualization', '1.0', {packages:['corechart']});
google.setOnLoadCallback(create_chart);
function create_chart() {
window.plotalot_chart_42_data = new google.visualization.DataTable();
window.plotalot_chart_42_data.addColumn('string', 'Labels');
window.plotalot_chart_42_data.addColumn('number', 'Values');
window.plotalot_chart_42_data.addColumn({'type': 'string', 'role': 'tooltip', 'p': {'html': true}});
window.plotalot_chart_42_data.addRows(
[['96 Users',96,'<strong>96 Users</strong><br />Criticized the Suction of the Bissell Spotlifter 1716B'],['31 Users',31,'<strong>31 Users</strong><br />Praised the Suction of the Bissell Spotlifter 1716B'],['300 Users',300,'<strong>300 Users</strong><br />Did Not Mention the Suction of the Bissell Spotlifter 1716B in their Review']]);
window.plotalot_chart_42_options = {title:'Breakdown of Comments About the Bissell Spotlifter 1716B\u0027s Suction Capability',backgroundColor:'#ffffff',is3D:true,pieSliceText:'value',legend:{position:'right'}
,tooltip: {isHtml: true}}
window.plotalot_chart_42 = new google.visualization.PieChart(document.getElementById('chart_42'));
window.plotalot_chart_42.draw(window.plotalot_chart_42_data, window.plotalot_chart_42_options);
}
Here's the HTML that I have in the article itself:
<div id="chart_42_container">{plotalot id="42"}
<i>If you're wondering why the total of the three groups displayed in this graphs is greater than the number of reviews we analyzed (425) for the Bissell Spotlifter 1716B, this is because there were 2 reviews that made both positive and negative remarks about this unit's suction.</i>
</div>
I tried to add a comment in italics below the graph in the space below the chart using the <em> tags, but this has been pushed down and overlaps the text in one of the paragraphs.
Here's the section with the piece chart: https://www.reviewminr.com/product-reviews/carpet-cleaner-reviews/bissell-spotlifter-1716b-review#suction
I know it must be possible to reduce these margins somehow as on the Extension's demo site, they have two of these same pie charts with none of these big white margins and they also have the comments in italics right below the the graphs.
Any ideas? Thanks in advance.
change height of chart_42_container
#chart_42_container{height:500px}
then the text will display in the container
the margin has to do with the height of the chart_42
#chart_42{height:398px;}