Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT! # Plotly in R Shiny

I am trying to develop shiny app which renders plot using plotly. I am able to get the plot using an example for plotly in shiny. But my graph does not look good. I am using ggplot2 for ploting the graph and then converting it to plotly using gg2list() and stored in a variable gg.
` output\$trendPlot <- renderGraph({

``````xaxislimits=as.character(sort(unique(as.numeric(subdata4()\$price_point)),decreasing = FALSE))

p <-  ggplot(data=subdata4(), aes(x=price_point, y=Price, fill=Seller))    +
geom_bar(stat="identity",position=position_dodge() ) +
xlab("Number of Units Sold") + ylab("Selling Price ")

gg <- gg2list(p)

# make edits with plotly syntax
gg\$layout <- list(legend = list(
x = 1,
y = 1,
bgcolor = "transparent"))

# Send this message up to the browser client, which will get fed through to
# Plotly's javascript graphing library embedded inside the graph
return(list(
list(
id = "trendPlot",
data = gg\$data,
layout= gg\$layout
)
))
``````

})

})`

But the plot is not good. And i dont understand whether to plot using ggplot2 then convert to plotly or us plot_ly() directly?

Kindly help me!

Any help will be appreciated.

Hey, can you be more specific about the issue with your plot? Perhaps you can attach an image of what you’re referring to.

Hey Kevin! Regret for the delay reply. I have attached the plotly image . As you can see i need to fix the scale of the x axis,labe of both the axis , the width of the bars and i also need to increase the width of the plot on the page.

Kindly help!

Does your plot render correctly if you’re just using `ggplot` ?

Yes the plot is correct! But the bars are really terrifying! Have to look into the the ranges of x-axis too!

Have you tried creating a plot using either `ggplotly()` or `plot_ly()` and then rendering the output with `renderPlotly` rather than `renderGraph`?
Here are some examples: https://plot.ly/r/shiny-tutorial/

I am able to plot the graph using plot_ly() , but can you tell me what can be the attribute for position_dodge in ggplot2 bar graph in plot_ly??
{"ft_lang_label":"__label__en","ft_lang_prob":0.650778,"math_prob":0.9129602,"size":1130,"snap":"2020-34-2020-40","text_gpt3_token_len":300,"char_repetition_ratio":0.103019536,"word_repetition_ratio":0.0,"special_character_ratio":0.26902655,"punctuation_ratio":0.10552764,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9901754,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-09-18T16:31:16Z\",\"WARC-Record-ID\":\"<urn:uuid:1a160781-e5f0-4433-b033-780931d6b6ca>\",\"Content-Length\":\"28445\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6fd14e3b-4d1a-4a4d-b8d9-c31f383e52e6>\",\"WARC-Concurrent-To\":\"<urn:uuid:3e01fd0a-26e5-417c-9862-107b4da78be1>\",\"WARC-IP-Address\":\"72.52.80.21\",\"WARC-Target-URI\":\"https://community.plotly.com/t/plotly-in-r-shiny/557\",\"WARC-Payload-Digest\":\"sha1:IIIIHDLLTMWE6S6HHS2L2GB6VJKGXR3D\",\"WARC-Block-Digest\":\"sha1:YPNJE4B43O6IDJCTOH536UKJ4RHUZ4NU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-40/CC-MAIN-2020-40_segments_1600400188049.8_warc_CC-MAIN-20200918155203-20200918185203-00527.warc.gz\"}"}